$('#save').click(function () { var nodes = zTree.getCheckedNodes(true); //獲取被勾選/未勾選的節點集合 // console.log(nodes); var id; //存放節點id var nodestring=""; //拼接節點的id爲一個字符串 var Sendjson={}; var resultjson; for(var i=0;i<nodes.length;i++) { id=nodes[i].id; idarry[i]=id; if(i<nodes.length-1) { nodestring += id + ','; } else nodestring+=id; } Sendjson.data=nodestring; var form = $('#Addmessge').serializeJSON();//表單信息 resultjson=Object.assign(Sendjson,form) //合併兩個對象 console.log(JSON.stringify(resultjson)); });
具體思路是先獲取勾選的節點,而後取相應的id值,而且把id值拼成字符串,而後將表單信息和拼接的字符串經過
Object.assign(Sendjson,form)進行合併node
data爲節點id,即已經勾選的id值,後面爲一個表單的信息 {"data":"1,11,111,1111,1112","Cname":"","Cencoding":"","Sequence":"","Ucategory":"test1","Rdetial":"test1","Ninformation":""}