0

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 :)

Chris
  • 599
  • 3
  • 11
  • 24
  • Why dont you use binding to feed your tree ? – Ji aSH May 02 '16 at 10:30
  • how should i bind the tree?It depends on an child parent relationship. When I use binding, the Tree don't know wich parent has which childs and so on. By the way I think I've got a problem with my browser cache or something like this, because the Error doesn't occur anymore :) – Chris May 02 '16 at 13:58

0 Answers0