作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
像这样的树状结构
var rootNode = {
id: 'root',
text : 'Root Node',
expanded : true,
children : [
{
id : 'c1',
text : 'Child 1',
leaf : true
},
{
id : 'c2',
text : 'Child 2',
leaf : true
},
{
id : 'c3',
text : 'Child 3',
children : [
{
id : 'gc1',
text : 'Grand Child',
children : [
{
id : 'gc11',
text : 'Grand Child 1',
leaf : true
},
{
id : 'gc12',
text : 'Grand Child 2',
leaf : true
}
]
}
]
}
]
};
var tree = new Ext.tree.TreePanel({
id: 'treePanel',
autoscroll: true,
root: rootNode
});
如何添加任何节点的子节点(比如“孙子”)?
我可以通过遍历树面板的根来访问子项,但是我在 Firebug 中控制台记录了它,它没有任何功能。对于未格式化的代码,我很抱歉,我无法对其进行格式化。
最佳答案
做这样的事情:
var treeNode = tree.getRootNode();
treeNode.expandChildren(true); // Optional: To see what happens
treeNode.appendChild({
id: 'c4',
text: 'Child 4',
leaf: true
});
treeNode.getChildAt(2).getChildAt(0).appendChild({
id: 'gc13',
text: 'Grand Child 3',
leaf: true
});
如果这是您需要的,请查看 NodeInterface 类。它有很多有用的方法: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.NodeInterface
关于javascript - 如何将子项添加到 TreePanel 中的节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10275448/
我是一名优秀的程序员,十分优秀!