cancel
Showing results for 
Search instead for 
Did you mean: 

Store the model path of the selected element of a tree

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

The problem is that my tree nodes are bound to the same model. So updating the model recreates all nodes and TreeNode's onClick handler can not invoke 'placeFocus' anymore (as the node is gone).

I solved this by using a second model for the activeGameElement property. The confusion of domain and app data bugged me anyways.

Answers (0)