如图:Delete.js里是抽离出来的每个页面共同的关于删除功能的ajax部分,现在一个页面里success里需要调用define模块里写的函数,应该怎么把这个函数传到Delete.js里??
如:case 7里的
Delete.js
var Delete =(function(){ var isAdding = true; /*权限管理*/ var firstGrid = $("#firstList").gtgrid("firstGrid"); var secondGrid = $("#secondList").gtgrid("secondGrid"); var thirdGrid = $("#thirdList").gtgrid("thirdGrid"); return function (){ this.del = function(id,url,ids,secondPId,thirdPId,deptKey){ $.ajax({ async : true, cache : false, url : url, data : {ids : ids}, dataType : "json", type : "post", success : function(data){ if(data.flag == "true"){ layer.msg("删除成功!", {icon: 1,time: 1000}); switch(id){ case 0:/*类别字典--类别*/ typeGrid.reload();/*reload刷新列表*/ codeGrid.load({"typeId" : typeId});/*load带参数,指定条件刷新*/ break; case 1:/*类别字典--字典*/ codeGrid.load({"typeId" : typeId}); break; case 2:/*岗位管理*/ isAdding = true; clear_form(); roleGrid.load({}); break; case 3:/*权限管理--一级权限*/ isAdding = true; clear_form(); firstGrid.reload();//重新加载数据 secondGrid.reload(); thirdGrid.reload(); break; case 4:/*权限管理--二级权限*/ isAdding = true; clear_form(); secondGrid.load({"parentId": secondPId}); thirdGrid.reload(); break; case 5:/*权限管理--三级权限*/ isAdding = true; clear_form(); thirdGrid.load({"parentId": thirdPId}); break; case 6:/*用户管理*/ isAdding = true; clear_form(); userGrid.load({"deptKey" : deptKey}); break; case 7:/*组织机构*/ queryDeptTreeWithoutRoot();//define里的关于ztree树的函数 // clear_form(); break; default: break; } }else{ layer.msg("删除失败!", {icon: 2}); } }, error : function(data){ layer.msg("网络故障!", {icon: 0}); } }); }; } }()); var DL = new Delete();//构造函数式 function clear_form(){ /*清空所有input,select/option,textarea*/ $(":input", "#form_data").not(":button,:hidden, :submit, :reset, flag='property'").val("").removeAttr("checked").removeAttr("selected"); $("#save_btn").nextAll("span").remove(); $("#form_data input").val(""); }