在layui layer 弹出层中加载 layui table

  • Post author:
  • Post category:其他


 1 layui.use('table', function(){
 2                 var table = layui.table;
 3                 layer.open({
 4                 type : 1,
 5                 area : [ "600px", '430px' ],
 6                 title : "选择模板",
 7                 maxmin : false,
 8                 content : '<div><table id="templateTable"></table></div>',
 9                 success : function(index, layero) {
10                     
11                       table.render({
12                         elem: '#templateTable'
13                         ,height: 300
14                         ,width:'100%'
15                        ,url: '${ctx}/oa/wzsc/oaWzscTemplate/listJson' //数据接口
16                        
17                         ,page: true //开启分页
18                         ,cols: [[ //表头
19                             {type:'radio'}
20                           ,{field: 'name', title: '模板名称', width:200, sort: true}
21                           ,{field: 'detail', title: '描述', width:330}
22                            ,{field: 'id', title: 'ID', width:200,hide:true}
23                           
24                         ]]
25                       });
26                     
27                 },
28                 
29                 btn : [ '确定', '关闭' ],
30                 yes : function(index, layero) {
31                         var checkStatus = table.checkStatus('templateTable'); //
32                         var datas = checkStatus.data;//选中的数据
33                         if(datas.length > 0){
34                             var selectData = datas[0];
35                              var tpid = selectData.id;
36                              var tpname = selectData.name;
37                              $('#tpId').val(tpid);
38                              $('#tpName').val(tpname);
39                              try{
40                                  layer.close(index);//关闭对话框.
41                              }catch(e){
42                                  setTimeout(function(){layer.close(index)}, 100);//延时0.1秒,对应360 7.1版本bug
43                              }
44                         }else{
45                             layer.msg('请选择一个模板!');
46                         }
47                          
48                     }
49                 });
50             });