Home  >  Article  >  Web Front-end  >  ExtJs dynamically generates the Json format of treepanel_jquery

ExtJs dynamically generates the Json format of treepanel_jquery

WBOY
WBOYOriginal
2016-05-16 15:49:401059browse

Add the "checked" attribute to the node and a checkbox will be automatically generated.

Get selected node

var nodeArray = "";
var nodesObj = mytree.getChecked();

var i;var length=nodesObj .length;
for (i = 0; i < length; i++) {
nodeArray += nodesObj[i].id + ',';   //允许多选的情况。如果不允许多选,就直接nodesObj[i].id 
}

nodeArray = nodeArray.substring(0, nodeArray.length - 1); 

Json format is as follows:

[{
"text": "To Do", 
"cls": "folder",
"expanded": true,
"children": [{
"text": "Go jogging",
"leaf": true,
"checked": true
},{
"text": "Take a nap",
"leaf": true,
"checked": false
},{
"text": "Climb Everest",
"leaf": true,
"checked": false
}]
},{
"text": "Grocery List",
"cls": "folder",
"children": [{
"text": "Bananas",
"leaf": true,
"checked": false
},{
"text": "Milk",
"leaf": true,
"checked": false
},{
"text": "Cereal",
"leaf": true,
"checked": false
},{
"text": "Energy foods",
"cls": "folder",
"children": [{
"text": "Coffee",
"leaf": true,
"checked": false
},{
"text": "Red Bull",
"leaf": true,
"checked": false
}]
}]
},{
"text": "Remodel Project", 
"cls": "folder",
"children": [{
"text": "Finish the budget",
"leaf": true,
"checked": false
},{
"text": "Call contractors",
"leaf": true,
"checked": false
},{
"text": "Choose design",
"leaf": true,
"checked": false
}]
}]

The above is the entire content of this article, I hope you all like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn