Function(parentNode, newNodes, isSilent)zTreeObj.addNodes

Overview[ depends on jquery.ztree.exedit js ]

Add nodes

In order to avoid duplication data resulting from repeated initialization, zTree v3.x will automatically clone node data when zTree initialized or add nodes. If you need to get the data objects within the zTree, please get the return value of this method.

Please use zTree object to executing the method.

Function Parameter Descriptions

parentNodeJSON

The additional node's parent node. If additional node is root node, please the parentNode is null.

Please ensure this node data object is a data object within zTree.

newNodesJSON / Array(JSON)

The node data's JSON object collection which need to increase, refer to 'treeNode treeNode data details'

1. zTree v3.x support to add single node, that is, if you only add a node, you can don't use the array.

2. If you use simple data model, please refer to the attributes within the 'setting.data.simpleData'.

isSilentBoolean

Set whether to automatically expand the parent node, after add nodes.

isSilent = true means: don't auto expand the parent node. Otherwise auto expand.

Return Array(JSON)

return the new nodes in zTree

If the newNodes is single data object, the return value is a array with length is 1.

Note: the node data JSON object in the return value is not equal to the JSON object in the 'newNodes'.

Examples of function

1. Add one root node to zTree which id is 'tree'

var treeObj = $.fn.zTree.getZTreeObj("tree");
var newNode = {name:"newNode1"};
newNode = treeObj.addNodes(null, newNode);

2. Add three root nodes to zTree which id is 'tree'

var treeObj = $.fn.zTree.getZTreeObj("tree");
var newNodes = [{name:"newNode1"}, {name:"newNode2"}, {name:"newNode3"}];
newNodes = treeObj.addNodes(null, newNodes);