jQuery EasyUI Tree Menu - Adding Nodes to a Tree Menu
This tutorial shows you how to append nodes to a Tree menu. We will create a food tree with fruit and vegetable nodes, and then add some other fruits to an existing fruit node.
Creating the food tree
First, we create the food tree, as shown in the following code:
Note that the Tree component is defined in
-
markup, and the tree node data is loaded from the URL "tree_data.json".
Getting the parent node
Then we select the fruit node by clicking on it, and we will add some other fruit data. Execute the getSelected method to get the node to process:
var node = $('#tt').tree('getSelected');
The return result of the getSelected method is a javascript object with id, text, and target properties. The target property is a DOM object referring to the selected node, and its append method will be used to append child nodes.
Appending nodes
var node = $('#tt').tree('getSelected');
if (node){
var nodes = [{
"id":13,
"text":"Raspberry"
},{
"id":14,
"text":"Cantaloupe"
}];
$('#tt').tree('append', {
parent:node.target,
data:nodes
});
}
After adding some fruits, you will see:
As you can see, using the easyui Tree plugin to append nodes is not that difficult.