在使用layui这款前台框架开发过程中经常会遇到很多问题例如
在列表页中加
var cols=[ //表头
{checkbox: true, },
{field: 'goodsName', width:"270", title: '商品名称',sort: true, },
{field: 'price', width:"170" ,title: '商品价格'},
{field: 'status', width:"140" ,title: '是否为新架',templet: '#titleTpl'},
{field: 'image', width:"190" ,height:"172",title: '图片',templet:'<div><img src="{{ d.image }}"></div>'},
{field: 'introduce', width:"203" ,title: '介绍'},
{field: 'createtime', width:"191" ,title: '更新时间'},
{title:'操作', width:"206", toolbar: '#table-useradmin-webuser',}
]
再添加一段js就大功告成了
<script type="text/html" id="titleTpl">
{{# if(d.status ==1){ }}
下架
{{# } else { }}
上架
{{# } }}
</script>
其实还有很多不懂的问题。例如:上面的这行代码
templet:'<div><img src="{{ d.image }}"></div>'
列表中读取图片路径,为什么一定是 d 把属性给携带出来,还得继续研究
<script type="text/html" id="titleTpl">
{{# if(d.data.sex =='男'){ }}
公的
{{# } else if(d.data.sex =='女') { }}
母的
{{# } else { }}
未知
{{# } }}
</script>
多条件这样写