javascript - 来自两个实体集的 xml 视图绑定数据
问题描述
我正在开发一个主从应用程序。我有一个带有列表控件的视图,并且我将它与来自名为“entityset1”的实体集的数据绑定。
Odata -> data from the entityset1
<serialno>122333</serialno>
我在同一服务中有另一个名为 entityset2 的实体集。
Odata -> data from the entityset2
<hdata>is Active</hdata>
来自上述 entityset2 的数据将仅使用过滤器 (/sap/opu/odata/sap/My_SRV/entityset2?$filter=(serialno=122333)
我现在正在尝试从 entityset2 中检索值并尝试将其绑定到列表中的一个属性。此列表已与 entityset1 数据绑定。
我的视图.xml。
<List id="list" select="_handleSelect">
<ObjectListItem id="MAIN_LIST_ITEM" press="_handleItemPress" title="{Name}">
<attributes>
<ObjectAttribute id="ATTR1" text="{serialno}" />
<ObjectAttribute id="ATTR2" text="{entityset2/hdata}" />
</attributes>
</ObjectListItem>
</List>
Controller.js(使用以下行绑定)
this.oList.bindAggregation("items", {
path: '/entityset1',
template: this.oListItem,
filters: this.searchFilters
});
var oserialnum = this.getView().getBindingContext().getObject().serialno;
var oHdata = new sap.ui.model.Filter("serialno", "EQ",oserialnum);
this.searchFilters = new sap.ui.model.Filter([oserialnum],true);
this.oList.bindAggregation("items",{
path : "/entityset2",
filters :this.searchFilters
});
但是,我在“this.getView().getBindingContext().getObject().serialno”这一行收到错误“无法读取未定义的属性 'getObject'”。
有人可以建议如何从 entity2 中检索数据并将其绑定到列表吗?
解决方案
您无法使用视图获取 BindingContext。阅读有关绑定 Context的更多信息- 它是指向模型数据中对象的指针。
此外,serialNo(您尝试从模型中检索的参数也是上下文相关的,即每个行项都不同)。
一种方法是:
列表的onListeItemPress事件
<ObjectListItem ... ... press="onListItemPress" >
在对应的Controller中
`onListItemPress:函数(oEvent){
var oserialnum = Event.getSource().getBindingContext("mainODataModel")..getProperty("serialNo")`
让我知道这是否有帮助。
推荐阅读
- javascript - 如何以角度反应形式验证日期字段?
- ios - 如何在ios swift中点击按钮时更改应用程序语言
- ios - 表格视图控制器上的粘性 UILabel
- primefaces - pe:blockUI 如何禁用淡入淡出效果?
- azure - 如何使用 curl 设置 Azure KeyVault 机密的值
- jquery - jQuery 日期选择器设置为空
- javascript - 如何找到唯一数量的数据属性
- python - Django 中的自定义 UserChangeForm
- java - Java中的Docx到Pdf转换器
- postgresql - RDS 上的 pg_upgrade 后权限被拒绝