EasyUI attaches tree nodes to the tree

Source: Internet
Author: User

@ Author YHC

This tutorial shows you how to attach a node to a tree. We will create a food tree Containing Fruit and Vegetable nodes, and then add some other fruits to an existing fruit node.

 

 

Create a foods (food) tree
First, we create a food tree and the code is like this.


[Html] view plaincopyprint? <Div style = "width: 200px; height: auto; border: 1px solid # ccc;">
<Ul id = "tt" class = "easyui-tree" url = "tree_data.json"> </ul>
</Div>

<Div style = "width: 200px; height: auto; border: 1px solid # ccc;">
<Ul id = "tt" class = "easyui-tree" url = "tree_data.json"> </ul>
</Div> note: the tree component is defined in the <ul> flag. The tree node data is loaded from the URL "tree_data.json.


Obtain the parent node
Then, we click the node to select the fruit (Food node). We will add some other food (fruit) data and execute the getSelected method to get the processing node.


[Javascript]
Var node = $ ('# tt'). tree ('getselected ');

Var node = $ ('# tt '). tree ('getselected'); The returned result of the getSelected method is a javascript object that has an id, text, and target attribute. The target attribute is a DOM object that references the selected node, its append method will use the append subnode.


Additional Node
[Javascript]
Var node = $ ('# tt'). tree ('getselected ');
If (node ){
Var nodes = [{
"Id": 13,
"Text": "Raspberry"
},{
"Id": 14,
"Text": "Cantaloupe"
}];
$ ('# Tt'). tree ('append ',{
Parent: node.tar get,
Data: nodes
});
}

Var node = $ ('# tt'). tree ('getselected ');
If (node ){
Var nodes = [{
"Id": 13,
"Text": "Raspberry"
},{
"Id": 14,
"Text": "Cantaloupe"
}];
$ ('# Tt'). tree ('append ',{
Parent: node.tar get,
Data: nodes
});
} When you add some fruit (food), you will see:

 


As you can see, it is not that difficult to use the tree plug-in of easyui to add nodes.

 

Author: yhc13429826359
 
 

 

 

 

 

 


 


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.