Skip to Content
0
Former Member
Feb 17, 2014 at 01:27 PM

Store the model path of the selected element of a tree

19 Views

Hey,

I plan to use the model path of the currently selected TreeNode of a Tree in various parts of my application. I could not find a bindable "selectedNode" property for trees, so I planned to set an "activeElement" property in my root model. I wanted to do this by setting the respective property in the selection handler of the tree.

My initial model data looks somethign like

{
     activeElement: undefined
}

When invoked, my handler

function(oControlEvent) {
  var path = oControlEvent.getParameters().nodeContext.getPath()
  var model = sap.ui.getCore().getModel();
  var elem = model.getProperty(path);
  model.setProperty("/activeGameElement", elem.isGameElement ? path : undefined);
}

throws the following error

Uncaught TypeError: Cannot call method 'placeFocus' of undefined TreeNode.js:14
sap.ui.commons.TreeNode.onclick TreeNode.js:14
sap.ui.core.Element._callEventHandles sap-ui-core.js:117
sap.ui.core.Element._handleEvent sap-ui-core.js:117
sap.ui.core.UIArea._handleEvent

Any ideas how to do this would help me alot.