This article mainly introduces how ztree obtains the checked node data and merges it with the form information. It has a certain reference value. Now I share it with you. Friends in need can refer to it.
$('#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)); });
The specific idea is to first get the checked node, then get the corresponding id value, and spell the id value into a string, and then combine the form information and the spliced characters Strings are merged through
Object.assign(Sendjson, form)
data为节点id,即已经勾选的id值,后面为一个表单的信息 {"data":"1,11,111,1111,1112","Cname":"","Cencoding":"","Sequence":"","Ucategory":"test1","Rdetial":"test1","Ninformation":""}
The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please Follow PHP Chinese website!
Related recommendations:
Learning about the selector of jQuery source code
The interface object of EventListener in addEventListener
The above is the detailed content of Ztree obtains the checked node data and merges it with the form information. For more information, please follow other related articles on the PHP Chinese website!