layui中根据条件判断使table单元格变色

今天接到一个需求,要求要根据后台给的条件判断这条数据是否过期,过期整行数据变色。

效果如下图所示:
在这里插入图片描述
代码如下图:
在这里插入图片描述

动态的根据后台给的条件使整行数据变色,也可以指定行变色,把下面的index变成你要指定行的数据就可以了。例如:that.find(“.layui-table-box tbody tr[data-index='” + 6+ “']”).css(“background-color”, “#FA8072”); // 行变色 (第6行变色)

done:function (res,curr,count) {
    
    
var that = this.elem.next();
 var preliminaryDayList = res.data;  // 拿到后台给的数据
 preliminaryDayList.forEach(function (item,index) {
    
     // 循环取后台给的条件的值
     if (item.isPreliminaryDay == true) {
    
    
         that.find(".layui-table-box tbody tr[data-index='" + index + "']").css("background-color", "#FA8072"); // 行变色
     }
 });
}

以上就是问题的解决方案。

猜你喜欢

转载自blog.csdn.net/li22356/article/details/124863010