TreeNode select () does not call select listener

I use the following code to get sap.ui.commons.TreeNode and select it.

var newNode = this.tree.getNodes()[typeIdx].getNodes()[typeArray.length - 1];
newNode.select();

Unfortunately, nothing happens. While it newNode.getIsSelected()returns true, handlers are not executed (none of them are selected on the tree and not selected on node).

PS I made sure that is newNode.getSelectable()true.

Has anyone successfully used the select () method of TreeNode?

Code example

Here is an example

Adding an item highlights the item, but a warning is displayed only when clicked with the mouse.

+3
source share
3 answers

Here is an example of how this works.

Here is the function we want to call when selecting node:

var sel = function(oEvent) {
    console.log(oEvent.getSource().getText() + " selected");
};

And here the tree with some nodes, nodes 1.1 and 1.2 has a handler:

new sap.ui.commons.Tree("tree", {
    nodes: [
        new sap.ui.commons.TreeNode({
            text: "1",
            nodes: [
                new sap.ui.commons.TreeNode({
                    text: "1.1",
                    selected: sel
                }),
                new sap.ui.commons.TreeNode({
                    text: "1.2",
                    selected: sel
                })
            ]
        }),
        new sap.ui.commons.TreeNode({
            text: "2"
        })
    ]
}).placeAt("content");

( ):

newNode = sap.ui.getCore().byId("tree").getNodes()[0].getNodes()[0]
newNode.select()

1.1 selected

, node.

+2

newNode.setIsSelected(true);

,

+1

After reading the exact requirement (the event is onSelectnot fired), I think there were two things:

  • the event was fireSelectednot explicitly triggered
  • The event selectwas set in the Tree element, not in the TreeNode template.

I updated your example to a new version: http://jsbin.com/hososexu/7/edit

+1
source

All Articles