开发中遇到需要根据返回的数据中的某一个字段的状态来改变当前行的字体颜色。
function planTitle(paramJson) {
planTable = table.render({
elem: '#plan-table',
headers: {"_token": _token},
url: zuulUrl,
where: {
paramJson: paramJson
},
title: '生产计划数据表',
cols: [[
{type: 'radio',fixed:'left'},//勾选框
{field: 'auditState', title: '审核状态',fixed:'left'},
{field: 'auditUserName', title: '审核人',fixed:'left'},
{field: 'makerUserTime', title: '制定时间',fixed:'left'}
]],
//根据字段状态改变行字体颜色
done: function () {
var index = -1;
$("[data-field='auditState']").children().each(function () {
index++;
if ($(this).text() === '已审核') {
$('tr').eq(index).css("color", '#00c600');
}
});
},
page: true,
parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
return {
"code": 0, //解析接口状态
"msg": res.message, //解析提示文本
"count": res.length, //解析数据长度
"data": list //解析数据列表
};
},
height: 'full-72',
});
}
代码参考地址:https://fly.layui.com/jie/31770/page/3/ @爷们无悔