gpt4 book ai didi

javascript - 如何将子项添加到 TreePanel 中的节点?

转载 作者:数据小太阳 更新时间:2023-10-29 05:02:58 25 4
gpt4 key购买 nike

像这样的树状结构

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 中控制台记录了它,它没有任何功能。对于未格式化的代码,我很抱歉,我无法对其进行格式化。

Tree Panel

最佳答案

做这样的事情:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com