(function(){ X.pageLogic['newkanban'] = { init :function(){ // console.log(X.DATA); //给两个下拉框赋值 var comboTree1,comboTree2; var KanBanData = []; for(let i in X.DATA.KanBanData){ // X.DATA.KanBanData[i][''] var arr = { 'name' : X.DATA.KanBanData[i]['name'], 'id' : X.DATA.KanBanData[i]['_id'], } KanBanData.push(arr); // console.log(X.DATA.KanBanData[i]); } console.log(KanBanData) comboTree1 = $('#newjustAnotherInputBox1').comboTree({ source : KanBanData, isMultiple: false }); comboTree2 = $('#newjustAnotherInputBox2').comboTree({ source : X.DATA.ProjectData, isMultiple: false }); // console.log('xxxx',$("#new-cha")); //叉图标关闭弹窗 $(".new-top .new-cha").click(function(){ layer.closeAll(); }); //取消按钮 $(".new-but-box .new-qx").click(function(){ layer.closeAll(); }); //我的看板,空间切换实践 $(".new-tab-box .new-tab div").click(function(){ $(".new-tab-box .new-tab div").removeClass('tabdata'); $(this).addClass('tabdata'); if($(this).html() == "我的看板"){ $("#newjustAnotherInputBox1").show(); $("#newjustAnotherInputBox2").hide(); }else { $("#newjustAnotherInputBox1").hide(); $("#newjustAnotherInputBox2").show(); } $("#newjustAnotherInputBox1").val(""); $("#newjustAnotherInputBox2").val(""); }) //确定按钮事件 $(".new-but-box .new-qd").click(function(){ var txt = $("#newname-txt").val();//获取新建名 var type ='kanban'//方便根据中文名获取对应id if($('#newjustAnotherInputBox1').val() != ""){ var Addlocation = $('#newjustAnotherInputBox1').val(); }else { var Addlocation = $('#newjustAnotherInputBox2').val(); type = "kongjian" } if(Addlocation){ //根据中文获取到对应的id var id = X.pageLogic.newkanban.matchingid(Addlocation,type); }else { // 为空时提示 alert('请选择添加的位置'); return; } var data = { 'name': txt, 'project_id': X.DATA.projectid, 'pid': id, } X.api('dashboard/create',"post",data,function(d){ // if(d.code == "ok"){ layer.msg(d,function(){ X.pageLogic.dashboard.freshMenu(X.DATA.projectid);//刷新侧边栏 //关闭对应弹窗 layer.closeAll(); }); // } }) }); }, //根据中文名获取侧边栏id matchingid : function(name,type){ var id, data; if(type == 'kanban'){ data = X.DATA.KanBanData; }else { data = X.DATA.ProjectData; } console.log(data); for(let i in data){ if(data[i]['name'] == name){ id = data[i]['_id'] }else { if(data[i]['children'].length > 0){ for(let j in data[i]['children']){ if(data[i]['children'][j]['name'] == name){ id = data[i]['children'][j]['_id'] } } }else { continue; } } } return id } }; })();