數據結構json
$list = [ ['id'=>1,'username'=>'2'], ['id'=>2,'username'=>2] ]; $json['code'] = 0; $json['msg'] = '1'; $json['count'] = 2; $json['data'] = $list; return json($json);
代碼:數據結構
<script> layui.use('table', function(){ var table = layui.table; table.render({ elem: '#tab-content' //,url:'/test/table/demo1.json' ,url: "{:url('user/lists')}" ,toolbar: '#toolbarDemo' ,title: '用戶數據表' ,cols: [[ {type: 'checkbox', fixed: 'left'} ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true} ,{field: 'name', title: '管理員', width:80} ,{field: 'role_name', title: '角色組', width:80, sort: true} ,{field: 'email', title: '郵箱', width:80} ,{field: 'status', title: '狀態', width: 177} ,{field: 'add_time', title: '添加時間', width: 150, sort: true} ,{field: 'update_time', title: '修改時間', width: 150, sort: true} ,{fixed: 'right', title:'操做', toolbar: '#barDemo', width:150} ]] ,page: 1 }); //頭工具欄事件 table.on('toolbar(test)', function(obj){ var checkStatus = table.checkStatus(obj.config.id); switch(obj.event){ case 'getCheckData': var data = checkStatus.data; layer.alert(JSON.stringify(data)); break; case 'getCheckLength': var data = checkStatus.data; layer.msg('選中了:'+ data.length + ' 個'); break; case 'isAll': layer.msg(checkStatus.isAll ? '全選': '未全選'); break; }; }); //監聽行工具事件 table.on('tool(test)', function(obj){ var data = obj.data; //console.log(obj) if(obj.event === 'del'){ layer.confirm('真的刪除行麼', function(index){ obj.del(); layer.close(index); }); } else if(obj.event === 'edit'){ layer.prompt({ formType: 2 ,value: data.email }, function(value, index){ obj.update({ email: value }); layer.close(index); }); } }); }); </script>