Search code examples
sapui5

How to get data from the current line?


I have a tree that looks as following:

enter image description here

and the XML view:

<Tree id="classTree" items="{path: 'Tree>/'}" toggleOpenState="onToggleOpenState">
    <CustomTreeItem>
        <FlexBox width="100%" alignItems="Center" justifyContent="SpaceBetween">
            <items>
                <Label text="{Tree>text}" wrapping="true"/>
                <Button icon="sap-icon://display" type="Transparent" press="onItemPress"/>
            </items>
        </FlexBox>
    </CustomTreeItem>
</Tree>  

As you can see, there is a button with the event press="onItemPress" that is implemented as following:

onItemPress: function (oEvent) {
    const oRow = oEvent.getSource().getParent().getParent();
    console.log(oRow.getItemNodeContext());
},

The return value is an object https://sapui5.hana.ondemand.com/#/api/sap.m.TreeItemBase/methods/getExpanded,that has the following value:

enter image description here

How to get the object, that is bind to the row?


Solution

  • What about:

    oEvent.getSource().getBindingContext("Tree").getObject();