有没有办法动态获取sap.Table对象的特定绑定?

Is there a way to dynamically get the specific binding of an sap.Table object?

我正在尝试编写通用的多用途 table filter/sorter。我提出的当前解决方案需要能够知道 table 行的文本 属性 的绑定。我可以很容易地获得绑定到 table 的模型,然后我可以获得它的所有属性。但这并没有说明 table 如何按行显示数据的顺序。理想情况下,这可以随时完成。不是行选择之类的东西。

我最接近获取属性的方法是获取已评估的绑定...

this.tableObject.getItems()[0].getCells()[0].getText()

此 returns 绑定的实际值,而不是绑定本身。

以及我可以用类似

检索的路径
this.tableObject.getItems()[0].getBindingContextPath()

哪个returns路径“/Rowsets/Rowset/0/Row/0”

但是当 table 中没有数据时,这也会失败。

table是这样设置的

<Table id="sap_Responsive_Page_0-content-build_simple_Table-1560756151819" 
width="auto" noDataText="No data" mode="None" showSeparators="All" growing="true" 
growingThreshold="20" growingScrollToLoad="true" class="sapUiResponsiveMargin" 
items="{path:'Model>/Rowsets/Rowset/0/Row', templateShareable:true}">

然后行设置如下

<Text text="{Model>RESOURCE}" width="auto" maxLines="1" wrapping="false" textAlign="Begin" 
textDirection="Inherit" visible="true"/>

I expect/want {Model>RESOURCE} 而是收到实际值 TEST。是否有不同的方式来获得此绑定?

试试下面的代码,获取每一行的绑定上下文。

没有别名模型

this.tableObject.getItems()[0].getBindingContext().getObject();

使用别名模型

this.tableObject.getItems()[0].getBindingContext("<alias model name>").getObject();

动态获取 table

中每一行的上下文

我们需要附加一个按下事件,以获取table.

中每一行的动态绑定上下文

查看

 <Table>
    <columns>
        <Column>
            <Text text=""/>
        </Column>

    </columns>
    <items>
        <ColumnListItem vAlign="Middle" type="Navigation" press="onPressItemTable">
            <cells>
                <Text text="{Model>RESOURCE}" width="auto" maxLines="1" wrapping="false" textAlign="Begin" textDirection="Inherit" visible="true"/>
            </cells>
        </ColumnListItem>
    </items>
</Table>

控制器

onPressItemTable : function(oEvent) {
    console.info(`Binding context of selected row: ${oEvent.getSource().getBindingContext().getObject()}`);
}