我正在尝试编写通用的多用途表过滤器/分类器。我提出的当前解决方案要求能够知道表行的text属性的绑定。我可以轻松获取绑定到表的模型,然后获取其所有属性。但这并没有说明表在行中显示数据的顺序。理想情况下,可以随时进行此操作。不在行选择之类的东西上。
与属性最接近的就是获取已经评估过的绑定了……
this.tableObject.getItems()[0].getCells()[0].getText()
这将返回绑定的实际值,而不是绑定本身。
以及我可以通过类似的方式获取的路径
this.tableObject.getItems()[0].getBindingContextPath()
返回路径“ / Rowsets / Rowset / 0 / Row / 0”
但是当表中没有数据时,这也会失败。
表格是这样设置的
<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"/>
我期望/想要{Model>RESOURCE}
,但收到实际值TEST
。有没有其他方法可以获取此绑定?
答案 0 :(得分:0)
请尝试以下代码,以获取每一行的绑定上下文。
this.tableObject.getItems()[0].getBindingContext().getObject();
this.tableObject.getItems()[0].getBindingContext("<alias model name>").getObject();
我们需要附加一个 press事件,以获取表中每一行的动态绑定上下文。
查看
<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()}`);
}