> 第一种方式 ``` <script> layui.use(["table","util","form","jquery","layer"], function(){ var table = layui.table ,util = layui.util ,form = layui.form ,layer = layui.layer ,$ = layui.jquery; table.render({ elem: '#table-jsinfo' ,url:"{:url('Jsinfo/jsinfoList')}" ,title: '车型推荐表' ,toolbar: 'default' ,cellMinWidth: 80 //全局定义常规单元格的最小宽度,layui 2.2.1 新增 ,cols: [[ {type: 'checkbox'} ,{field:'js_id', title:'ID', width:80, unresize: true, sort: true} ,{field:'js_phone', title:'手机号',width:260,sort: true} ,{field:'js_shebao', title:'社保'} ,{field:'js_liushui', title:'代发流水',} ,{field:'js_chexing', title:'心仪车型',} ,{field:'js_add_time', title:'添加时间',templet:function (res) { return util.toDateString(res.js_add_time = (res.js_add_time * 1000)); }} ,{title:'操作', toolbar: '#barJsinfo'} ]] ,page: true ,done:function (res,page,count) { //分类显示中文名称 $("[data-field='js_shebao']").children().each(function(){ if($(this).text()=='0'){ $(this).text("没社保") }else if($(this).text()=='1'){ $(this).text("半年") }else if($(this).text()=='2'){ $(this).text("半年到一年") }else if($(this).text()=='3'){ $(this).text("一年到两年") }else if($(this).text()=='4'){ $(this).text("两年以上") } }) } }); }); </script> ``` > 第二种方式 ``` //在解析单元格的时候自定义列为这样 {field:'js_chexing', title:'心仪车型',templet:'#JS_chexingBar'} //通常简单的解析 <script type="text/html" id="JS_chexingBar"> {{# if(d.js_chexing == 1){ }} 轿车 {{# }else if(d.js_chexing==2){ }} SUV {{# }else { }} MPV {{# } }} </script> //行内简单一点 {field: 'ordertype', title: '订单类型', align:'center',templet:function(d){ return d.ordertype == "elvan" ? "代购" : "私有"; }} ``` > PS 比较复杂的需求 ``` <script type="text/html" id="stateBar"> {{# if(d.state == '0'){ }} <input type="radio" name="state{{d.id}}" value="{{d.id}}" title="已提交" lay-filter="lockDemo" {{ d.state==0 ? 'checked' : '' }}>&nbsp; <input type="radio" name="state{{d.id}}" value="{{d.id}}" title="处理中" lay-filter="lockDemo" {{ d.state==1 ? 'checked' : '' }}>&nbsp; <input type="radio" name="state{{d.id}}" value="{{d.id}}" title="已处理" lay-filter="lockDemo" {{ d.state==2 ? 'checked' : '' }}> {{# } else if(d.state == '1') { }} <input type="radio" name="state{{d.id}}" value="{{d.id}}" title="已提交" lay-filter="lockDemo" {{ d.state==0 ? 'checked' : '' }}>&nbsp; <input type="radio" name="state{{d.id}}" value="{{d.id}}" title="处理中" lay-filter="lockDemo" {{ d.state==1 ? 'checked' : '' }}>&nbsp; <input type="radio" name="state{{d.id}}" value="{{d.id}}" title="已处理" lay-filter="lockDemo" {{ d.state==2 ? 'checked' : '' }}> {{# } else { }} <input type="radio" name="state{{d.id}}" value="{{d.id}}" title="已提交" lay-filter="lockDemo" {{ d.state==0 ? 'checked' : '' }}>&nbsp; <input type="radio" name="state{{d.id}}" value="{{d.id}}" title="处理中" lay-filter="lockDemo" {{ d.state==1 ? 'checked' : '' }}>&nbsp; <input type="radio" name="state{{d.id}}" value="{{d.id}}" title="已处理" lay-filter="lockDemo" {{ d.state==2 ? 'checked' : '' }}> {{# } }} </script> ```