访问 Ext JS 树中 TreeNode 的叶子
我正在使用 Ext JS 库来创建我的应用程序。我有一个包含树节点和子树节点的树面板。这些树节点具有我希望能够访问的叶子。我已经搜索了一段时间,但找不到属性函数来访问叶子:(
这里有一些代码:
var i;
var j = 0;
var selectedLayers = new Array();
while(layerRoot.lastChild.hasChildNodes()){
alert(layerRoot.lastChild.firstChild);
for(i = 0; i < layerRoot.lastChild.firstChild.childNodes.length; i++){
if(layerRoot.lastChild.firstChild.childNodes[i].isSelected()){
selectedLayers[j] = layerRoot.lastChild.firstChild.childNodes[i].attributes.text;
alert(selectedLayers[j]);
j++;
}
}
layerRoot.lastChild.removeChild(layerRoot.lastChild.firstChild);
}
layerRoot.removeChild(layerRoot.lastChild);
我尝试过layerRoot.lastChild.firstChild.childNodes,但这不起作用,因为layerRoot的子节点.lastChild.firstChild 是叶子:(。非常感谢您的时间和反馈
。elshae
I am using the Ext JS library for creating my application. I have a tree panel that has tree nodes and children tree nodes. These tree nodes have leafs that I would like to be able to access. I've been searching for a while, but cannot find a function of property to access the leafs :(
Some code is here:
var i;
var j = 0;
var selectedLayers = new Array();
while(layerRoot.lastChild.hasChildNodes()){
alert(layerRoot.lastChild.firstChild);
for(i = 0; i < layerRoot.lastChild.firstChild.childNodes.length; i++){
if(layerRoot.lastChild.firstChild.childNodes[i].isSelected()){
selectedLayers[j] = layerRoot.lastChild.firstChild.childNodes[i].attributes.text;
alert(selectedLayers[j]);
j++;
}
}
layerRoot.lastChild.removeChild(layerRoot.lastChild.firstChild);
}
layerRoot.removeChild(layerRoot.lastChild);
I've tried layerRoot.lastChild.firstChild.childNodes, but this doesn't work since the children of layerRoot.lastChild.firstChild are leafs :(. Your time and feedback is very appreciated.
elshae
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也刚刚开始使用 TreePanel,我认为您必须编写函数来遍历树并使用
leaf
属性测试节点是否是叶子。如果您想在叶子上执行特定函数,则可以使用cascade()
自动遍历树,并沿途测试leaf
属性并执行你的代码。I just started playing around with TreePanel too, I think you have to write your function to traverse the tree and test if the nodes are leaves using the
leaf
property. If you have a particular function you want to execute on the leaves, you can usecascade()
to automatically traverse the tree for you, testing for theleaf
property along the way and executing your code.您应该查看 TreePanel,我认为 TreeGrid 在最新的 ext 版本(3.3)中可能已被弃用。它有大量的 get/set/traversal 函数,请在此处的 API 中查看:http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreePanel
You should check out TreePanel, I think TreeGrid might be deprecated in the latest ext version (3.3). It has a ton of get/set/traversal functions, check it out in the API here: http://dev.sencha.com/deploy/dev/docs/?class=Ext.tree.TreePanel