Reputation: 584
I use the following code to get a sap.ui.commons.TreeNode and to select it.
var newNode = this.tree.getNodes()[typeIdx].getNodes()[typeArray.length - 1];
newNode.select();
Unfortunately though, nothing happens. While newNode.getIsSelected()
returns true, no handlers are executed (neither select on the tree nor selected on the node).
P.S. I made sure newNode.getSelectable()
is true.
Did anyone use TreeNode's select() method sucessfully?
Code example
Adding an element does highlight the element but the alert is only shown when clicking with the mouse.
Upvotes: 3
Views: 1306
Reputation: 4920
Having read the exact requirement (the event onSelect
not being fired), I think there were two things missing:
fireSelected
event was not explicitly firedselect
event was set on the Tree element rather than the TreeNode templateI have updated your example to a new version: http://jsbin.com/hososexu/7/edit
Upvotes: 1
Reputation: 3105
Here's an example of how this works.
Here's the function that we want to call on the node selection:
var sel = function(oEvent) {
console.log(oEvent.getSource().getText() + " selected");
};
And here's the tree with some nodes, nodes 1.1 and 1.2 have the 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");
And when we do this (based on your example):
newNode = sap.ui.getCore().byId("tree").getNodes()[0].getNodes()[0]
newNode.select()
we get
1.1 selected
in the console, and the the node is highlighted.
Upvotes: 2
Reputation: 4920
Can you try using newNode.setIsSelected(true);
That works for me
Best, Robin
Upvotes: 1