The web code written today is stuck here for more than an hour.
The parameters of the zTree addNodes (parentNode, newNodes, isSilent) method are too confusing.
So I think this place uses json strings. It may be because the background code is too much written. After the parent and child node objects are serialized using the JSON. stringify () method, the addNodes () method is passed in, prompting that the expression format is incorrect. I thought it was my json method that was used incorrectly. Then I spliced the json method and made various modifications.
I had to find a colleague who used this plug-in to help me.
First, the JSON here is a JSON object. It cannot be a JSON string. In js, a json string uses the type of operator to obtain the "string" type, while operating the JSON object, the result is an "object" type. This is an essential difference. The Data Types of the first two parameters are not JSON strings, all of which are JSON objects. Second, the parentNode parameter is not a common JSON object. It must be the zTree framework that has been customized by the zTree object method. This zTree example is not clear at all. The parentNode parameters of the addNodes method are both null ...... This is the first time you use this plug-in API.
The code I wrote for adding nodes is for reference only:
Function ZtreeNode (id, pId, name) {// defines the ztree node class this. id = id; this. pId = pId; this. name = name ;}
Var orgId = $ (text ). attr ("data-tt-org-id"); var parentOrgId = $ ("input [name = 'jo. fid'] "). val (); var name = $ ("# groupName "). val (); var childZNode = new ZtreeNode (orgId, parentOrgId, name); // construct a subnode var treeObj = $. fn. zTree. getZTreeObj ("orgTree"); // obtain the ztree object var parentZNode = treeObj. getNodeByParam ("id", parentOrgId, null); // obtain the parent node treeObj. addNodes (parentZNode, childZNode, true );