on ‎2018 Oct 25 2:09 PM
Hi,
I am trying to change the example from the basic tree. I want to keep the title of the StandardTreeItem each time I expand a node (without selection).
The xml:
<Tree
id="Tree"
items="{path: '/'}"
toggleOpenState="onToggle">
<StandardTreeItem id="item" title="{text}"/>
</Tree>
In the controller I have this:
onInit : function (evt) {
// set explored app's demo model on this sample
var oModel = new JSONModel(jQuery.sap.getModulePath("sap.m.sample.Tree", "/Tree.json"));
this.getView().setModel(oModel);
},
onToggle: function(oEvent) {
var data = this.getView().getModel().getData();
var lItem = oEvent.getParameters().getBindingContext("data");
console.log(lItem);
},
When I am trying this, I am getting that the lItem is undefined. Any ideas about why or how can I fix this?
Request clarification before answering.
Hi, iliana what you're doing wrong is how you're reading the parameters. I would suggest you read the API reference of the toggleOpenState event before.
In your specific case to get the bindingContext of the opened item you can simply do:
onToggle: function(oEvent) {
var lItem = oEvent.getParameter("itemContext");
console.log(lItem); // Item binding context
console.log(lItem.getObject()); // this will print the JSON object inside the item you're binded to the tree
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 5 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.