关于layui中table.on以及操作按钮的使用以及Uncaught ReferenceError: table is not defined错误解决办法

因为之前将下面这段代码放错了位置  导致一直报错,且无法触发事件

有两个注意事项:1、下面的程序中tool(demo)  中的demo是table表的lay-filter的名字  如我的代码中:所以我需要将下面的那个demo改为test

2、关于这段代码放的位置,千万不要把它放到js文件里面去,一般你导入layui时,一般是通过中间存放use table

 它应该放的位置如下图所示:  不要放到layui.use() 的括号外面去了

 layui.use('table', function(){ table.on()放的位置  })

 放到外面去的话,浏览器会出现这个错误(这个耽误了我很久):

关于layui中table.on以及操作按钮的使用以及Uncaught ReferenceError: table is not defined错误解决办法_第1张图片

 //编辑,删除,发布申请
     table.on('tool(demo)', function(obj){
         var data = obj.data;
         // console.log(data)
         if(obj.event === 'check'){
           //  console.log(data.id);
             $('.textCon').val("");
             layer.open({
                 title: '发布申请'
                 ,type: 1
                 ,maxmin:true
                 ,area: ['700px','570px']
                 ,content: $('#toExamine')
                 ,btn: ['申请', '取消']
                 ,yes: function(index, layero) {
                     var userName = $('#userRadio').val();
                     if(userName == null || userName == ''){
                         layer.msg("请选择用户", {icon: 2, time: 2000});
                         return;
                     }
                     var describe = $('.textCon').val();
                     if(describe == null || describe == ''){
                         layer.msg("请输入内容", {icon: 2, time: 2000});
                         return;
                     }
                     $.ajax({
                         type: "post",
                         url: "/approval/application/save.afca",
                         dataType:'json',
                         data: {
                             name: data.toolName,
                             targerId: data.id,
                             status: 0,
                             type: 'script',
                             describe: $('.textCon').val(),
                             key: 'script',
                             supUser:userName
                         },
                         success: function (data) {
                             var message = data.msg;
                             if(data.code === '0'){
                                 obj.del();
                                 layer.close(index);
                                 layer.msg(message,{icon: 1,time:2000});
                                 tableObj.reload({
                                     url:'/cd/workPlatform/tool/queryTools.afca'
                                 });
                             } else {
                                 layer.alert(message, {
                                     icon: 2,title:'提示'
                                 });
                                 return;
                             }
                         },
                         error: function () {
                         }
                     })
                 }
             });
             getAllUser();
             $('.laytable-cell-checkbox').eq(0).empty();
         } else if(obj.event === 'del'){
             layer.confirm('确认删除么', function(index) {
                 $.ajax({
                     type: "post",
                     url: "/cd/workPlatform/tool/remove.afca",
                     dataType:'json',
                     data: "id="+data.id,
                     dataType: "json",
                     success: function (data) {
                       //  console.log(data);
                         var message = data.msg;
                         var code = data.code;
                        // console.log(message);
                        // console.log(code);
                         if(data.code === '0'){
                             //obj.del();
                             layer.close(index);
                             layer.alert(message,{icon: 1,time:2000});
                             tableObj.reload({
                                 url:'/cd/workPlatform/tool/queryTools.afca'
                             });
                         } else {
                             layer.alert(message, {
                                 icon: 2,title:'提示'
                             });
                             return;
                         }
                     },
                     error: function () {
                     }
 
                 })
             });
             //编辑脚本定义
         }else if(obj.event === 'edit'){
             //之前版本
            // window.location.href='workToolEdit.html?toolSceneId='+data.toolSceneId+'&'+'id='+data.id;
             //脚本编辑弹出层
             var name = encodeURIComponent(data.toolName);
            // console.log(data.toolName);
             parent.layer.open({
                 type: 2,
                 title: '编辑脚本定义',
                 // title:data.to,
                 shadeClose: true,
                 shade: 0.8,
               //  maxmin: true,
                 area: ['100%', '100%'],
                 content: 'html/taskManagement/scriptManagement/workToolEdit.html?toolSceneId='+data.toolSceneId+'&'+'id='+data.id
             });
         }else if(obj.event === 'showInformation'){
             //脚本展示弹出层
             var name = encodeURIComponent(data.toolName);
           //  console.log(data.toolName);
             parent.layer.open({
                 type: 2,
                 title: '展示脚本定义',
                 // title:data.to,
                 shadeClose: true,
                 shade: 0.8,
                // maxmin: true,
                 area: ['100%', '100%'],
                 content: 'html/taskManagement/scriptManagement/showScriptInformation.html?id='+data.id
             });
         }
         else if(obj.event ==='jump'){
             // window.location.href='openScriptParaVerManagement.html?toolId='+data.id;
             var name = encodeURIComponent(data.toolName);
           //  console.log(data.toolName);
            parent.layer.open({
                 type: 2,
                 title: '参数版本管理',
                 // title:data.to,
                 shadeClose: true,
                 shade: 0.8,
                // maxmin: true,
                 area: ['100%', '100%'],
                 content: 'html/taskManagement/scriptManagement/openScriptParaVerManagement.html?toolId='+data.id+"&jiaoben="+name+"&banben="+data.version+"&scriptLanguage="+data.scriptLanguage+"&categoryName="+data.categoryName+"&=status"+data.status
             });
         }
     });

Uncaught ReferenceError: table is not defined这个错误  笔者遇到的是因为将table.on放错了位置(放于table.use()外面去了)

你可能感兴趣的:(大后端开发学习,IT成长笔记,spring,springboot,springcloud,layui)