문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top