layui table列中参数转换(1=汽车 2=火车 3=飞机) & layui table列中的值替换 (已解决)

林逗哥 于 2018-11-27 19:39:10 发布
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
问题: 类别属性为sort 后台数据库存的是1 2 3 但是显示的需要转换成 人才 政策 项目
代码:方法一
页面:
<script type="text/html" id="tranSort">
{{# if (d.sort==1) { }}
<span>人才</span>
{{# } else if(d.sort==2) { }}
<span>政策</span>
{{# } else{ }}
<span>项目</span>
{{# }}}
</script>
小插曲:
本想这种花括号是成对出现,伸展开更容易理解代码,万万没想到这种写法是不认识的,报错,这是因为这个模板语言不支持
js:
cols : [ [ // 表头
{
field : 'check',
title : ' ',
fixed : 'left',
type : 'checkbox'
}, {
field : 'investId',
title : '序号',
sort : true,
width : 80
}, {
field : 'title',
title : '标题'
}, {
field : 'sort',
title : '类别',
templet:'#tranSort'
}
, {
field : 'pubdate',
title : '发布时间'
},{
fixed : 'right',
title : '操作',
align : 'center',
toolbar : '#barDemo',
width : 180
} ] ]
,
方法二
js:
done:function(res, curr, count){
console.log(res);
$("[data-field = 'sort']").children().each(function(){
if($(this).text() == '1'){
$(this).text("人才");
}else if($(this).text() == '2'){
$(this).text("政策");
}else if($(this).text() == '3'){
$(this).text("项目");
}
})
console.log(curr);
console.log(count);
}
效果:

相关知识
layui 教程 => 干货
layui php移动端适配方案
LaTeX表格自定义行高+自定义列宽+大表格自适应页面宽度
前端——table标签和form标签和控件:table,input的type类型,select和option,label,textarea
汽车数据的可视化分析(R)
SSM + Layui实现的后台管理系统
layui快速搭建一个后台管理系统
解决无法获取 GridView 隐藏列值问题
图像增强——传统算法伽马校正实现暗光增强(附Python代码)
使用pandas绘制两列csv的直方图
原文链接: layui table列中参数转换(1=汽车 2=火车 3=飞机) & layui table列中的值替换 (已解决) https://www.huajiangbk.com/newsview1155776.html
| 上一篇: 《高花自然低花**叫牌法》 | 下一篇: Java运算符及运算符优先级详解... |





