如何从当前行获取数据?

时间:2018-08-24 06:07:54

标签: sapui5

我有一棵树,如下所示:

enter image description here

和XML视图:

<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>  

如您所见,有一个带有事件press="onItemPress"的按钮,其实现如下:

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

返回值是对象https://sapui5.hana.ondemand.com/#/api/sap.m.TreeItemBase/methods/getExpanded,that,具有以下值:

enter image description here

如何获取绑定到行的对象?

1 个答案:

答案 0 :(得分:3)

那又怎么样:

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