1

I am a newbie programming in SAP UI5, and using the sap.m.Tree object I have had the need to access some of its properties from the view. But I think this is not possible without making changes in the model.

The tree object allows to feed it with a JSONModel that has nodes in the form of hierarchy, it is only necessary to relate parent and child in a very simple type structure:

{
    "text": "Node1",
    "nodes": [
        {
            "text": "Node1-1",
            "nodes":[ "..." ]
        }
    ]
}

Once the tree is created, the component generates extra information such as whether the element is a leaf (it has no children), whether in which level the item is, etc. data that I do not have in the model.

At the time of using it in the view, in this way

<Tree id="Tree" items="{/}">
    <StandardTreeItem title="{text}" mode="Active"/>
</Tree>

I need, for example, to change mode from "Active" to "Navigation" only for nodes that are leaf, but I think it is not possible to access the sap.m.StandardTreeItem own methods like isLeaf(), isTopLevel() or getLevel().

My idea was to use it in an expression like

<StandardTreeItem title="{text}" mode="{= ${this.isLeaf()} ? 'Navigation' : 'Active' }" />

I also tried with a formatter but I think the only thing it passes as a parameter is the value of the field.

Is there any way to do this? Or the only way is that the model has already calculated an attribute with "leaf": true, when it is leaf?

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Xavi Polo
  • 13
  • 1
  • 3

0 Answers0