Element-ui中Table表中el-table-column列数据的布尔值回填

    前端使用vue+element-ui,我们经常会使用table来展示从后台请求回来的数据,但是,如果被请求回来数据是Boolean类型的时候,在table的列上,就不能像普通的字符串数据一样,被展示出来,这个时候,我们需要做的就是对布尔值数据进行格式的转化。

例如:

<el-table :data="rows" ref="datagrid" border="true" highlight-current-row="true" style=" 100%">

<el-table-column prop="tableId" label="表id" :show-overflow-tooltip="true"> </el-table-column>

<el-table-column prop="pk" label="是否为主键" :formatter="formatBoolean"
:show-overflow-tooltip="true"></el-table-column>


</el-table>
列“是否为主键”的后台返回值为布尔值‘true’或‘false’,我们要想让其在页面上展示,就用:formatter="formatBoolean"属性,对该值进行格式转换,JS代码如下:

/*布尔值格式化:cellValue为后台返回的值
*/
formatBoolean: function (row, column, cellValue) {
var ret = '' //你想在页面展示的值
if (cellValue) {
ret = "是" //根据自己的需求设定
} else {
ret = "否"
}
return ret;
},
好了,这样的话就可以看到了,日期类型的数据展示与这个同理!

原文地址:https://www.cnblogs.com/51net/p/13212607.html