What should I do if I want to achieve the TreeGrid effect without opening the official example? I implemented it in this way.
Copy codeThe Code is as follows: var root = new Ext. tree. TreeNode ({
Text: 'root node ',
Expanded: true
});
Tree. setRootNode (root );
Var nodes = {};
Nodes. children = mydata;/* json data of TreeGrid [{......}, {……}] */
Function appendChild (node, o ){
If (o. children! = Null & o. children. length> 0 ){
For (var a = 0; a <o. children. length; a ++ ){
Var n = new Ext. tree. TreeNode ({
Task: o. children [a]. task,
Duration: o. children [a]. duration,
User: o. children [a]. user,
IconCls: o. children [a]. iconCls
});
Node. appendChild (n );
AppendChild (n, o. children [a]);
}
}
}
AppendChild (root, nodes );
Looking at the source code, we know that TreeGrid inherits from TreePanel.
So root is the data source instead of store,
Based on the principle of loading json data to the tree, we can load json data to treeGrid in this way, instead of dataUrl: 'treegrid-data. isn't it very easy to load the json file like this?