layui表单使用开关滑块和复选框,渲染后台数据方法
提示:整个表格要在form标签内
定义开关模板
class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">//这个是开关滑块模板 //这个是表单渲染数据和初始化调用后台数据(通过向接口传id获取特定数据,数组形式)
↓↓定义复选框
table.render({ elem: '#js_table_reource_invite_supplier_index_table', data:[], cellMinWidth: 80, maxHeight:300, loading: true, even: true, method: 'POST', cols: [ [ {type: 'numbers', title: '序号'}, {type: 'checkbox', width: 50}, {field: 'provider_name', title: '供方名称',width: 150}, {field: 'is_qualified', title: '是否合格',width: 100, align: 'center',templet:function(row){ var html = ""; if(row.is_qualified == 1){ html += " checked "; } html += ">"; return html; }},//这里是复选框引用 ]], done: function (obj) { layer.closeAll(); form.on('checkbox(checkboxIsSelected)', function(data){ var _index = $(data.elem).attr('table-index')||0; if(data.elem.checked){ obj.data[_index].is_qualified = data.value; }else{ obj.data[_index].is_qualified = 2; } }); } });