Example of adding a node to the zTree framework

Source: Internet
Author: User

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 );


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.