访问 Ext JS 树中 TreeNode 的叶子

发布于 2024-09-28 18:02:55 字数 1003 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜`诱少女 2024-10-05 18:02:55

我也刚刚开始使用 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 use cascade() to automatically traverse the tree for you, testing for the leaf property along the way and executing your code.

窝囊感情。 2024-10-05 18:02:55

您应该查看 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文