Good morning, I got a problem with my Tree control in SAPUI5. At first I'll give you a short code snippet:
loadChildNodes : function(parentID){
if (parentID != "" && parentID != "_1") {
var oTree = sap.ui.getCore().byId("oTree");
var aTreeNodes = oTree.findAggregatedObjects(true);
var oParentNode;
for (var index = 0; index < aTreeNodes.length; index++) {
if (aTreeNodes[index].getId() === parentID) {
oParentNode = aTreeNodes[index];
}
}
var oJSON = new sap.ui.getCore().getModel("oJSON");
var rootPath = oJSON.getProperty("/ORG_UNITS");
for (key in rootPath) {
if (rootPath[key].parent === parentID.slice(1,
parentID.length)) {
var oChildNode = new sap.ui.commons.TreeNode({
id : "_" + rootPath[key].id,
text : rootPath[key].name,
expanded : false,
hasExpander : true
});
var indexOfParentNode = oTree.indexOfNode(oParentNode);
alert(indexOfParentNode);
oTree.removeNode(oParentNode);
oParentNode.add(oChildNode);
oTree.insertNode(oChildNode, indexOfParentNode);
}
}
}
}
Now here is my problem:
I want to build an dynamic tree. For this, every time the expander is pressed in the TreeView, the childs of this parent are loaded. So I do some checks and then I want to add the childs. So ine first lines, I get the parent element var oParentNode
in the tree var oTree
. Then I build the childs. Now I want to get the index of oParentNode
inside oTree
. Now that i've found the index I remove the parent and add all childs to it, and then insert it into the tree.
The problem now is, that the index of the oParentNode
is always -1 ... why??
Thanks for every help :)