Skip to Content
0
Feb 25, 2015 at 07:01 AM

UI5 Tree binding issue

395 Views

Hi Experts,

I have a problem displaying nodes in a tree.

Users of my tree should be able to add and remove nodes.

The tree must has only 2 levels, first level always has the same nodes. The second level nodes could be added or deleted by a user.

My model looks like this:

var model = {[

{

"displayName" : "runner 1",

"id" : "runner_1",

"configs": [

{

"displayName": "config 11",

"id": "config_11",

"settings" : {}

},

{

"displayName": "config 12",

"id": "config_12",

"settings" : {}

}

]

},

{

"displayName" : "runner 2",

"id" : "runner_2",

"configs": [

{

"displayName": "config 21",

"id": "config_21",

"settings" : {}

},

{

"displayName": "config 22",

"id": "config_22",

"settings" : {}

}

]

}

]}

After binding the model to the tree every things looks great except that there 3 levels in the tree (settings child is displayed).

My binding code looks like this:

var oTreeNodeTemplate = new sap.ui.commons.TreeNode();

oTreeNodeTamplate.bindProperty("text", "displayName");

this.oRunConfigurationTree.bindAggregation("nodes", "/oRunners", oTreeNodeTemplate);

In order to remove the third level i did a trick that worked. When i build the model for the first time or adding/removing a second level node i run the following code:

1. add "displayName" = "__filtered__" attribute to each "settings" object.

2. var oFilter = new sap.ui.model.Filter("displayName", sap.ui.model.FilterOperator.NE, "__filtered__");

3. this.getView().oRunConfigurationTree.getBinding("nodes").filter([oFilter]);

Is it the right approach to remove objects that should not be displayed in a tree ?

Can i somehow restrict a ui5 tree to show only 2 levels of nodes ?

Regards,

Slavik