LayUI 性别前端显示

在程序开发中,经常使用1=男生,2=女生,在数据库中存储的字段值也是1或2,在LayUI前端显示如何解决这个问题。

解决办法:通过定义字段的template渲染函数,解决字段值转换显示问题。

核心功能代码片段:

cols: [
    	[
	      {field:'id', width: 50, title: 'ID'}
	      ,{field:'name', title: '员工名称', align: 'center'}
	      ,{field:'code', title: '员工编码', align: 'center'}
	      ,{field:'sex', title: '性别', align: 'center',  templet: function(d){if(d.sex == 1){return '男'}else{return '女'}}}
	      ,{field:'birthday', title: '员工生日', align: 'center', templet:"<div>{{layui.util.toDateString(d.birthday)}}</div>"}
	      ,{field:'telephone', title: '电话号码', align: 'center'}
	      ,{field:'workYear', title: '工作年限', align: 'center'}
	      ,{title:'操作', align: 'center', toolbar: '#operation', width:150}
    	]
   	]

LayUI 性别前端显示

 前端效果截图:

LayUI 性别前端显示

 

上一篇:微信小程序自制底部菜单栏


下一篇:NX二次开发-向量乘矩阵变换的结果说明