zl程序教程

您现在的位置是:首页 >  后端

当前栏目

extjs3.31TreeGrid实现静态页面加载json到TreeGrid里面

静态JSONJSON 实现 页面 加载 里面
2023-06-13 09:14:49 时间
想要实现TreeGrid的效果,打开官方例子却看不到效果,怎么办呢?我是这样实现的
复制代码代码如下:

varroot=newExt.tree.TreeNode({
text:"根节点",
expanded:true
});
tree.setRootNode(root);
varnodes={};
nodes.children=mydata;/*TreeGrid的json数据[{……},{……}]*/
functionappendChild(node,o){
if(o.children!=null&&o.children.length>0){
for(vara=0;a<o.children.length;a++){
varn=newExt.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);

看源码我们知道TreeGrid继承于TreePanel
所以root才是数据源而不是store,
根据加载json数据到树的原理,同理我们可以这样加载json数据到treeGrid,而不再为dataUrl:"treegrid-data.json"这样的加载方式而烦恼了,是不是很简单呢?