我是SAPUI5的新手。我有一个场景:
主 - 详细信息页面(来自SAP Web IDE提供的主 - 详细信息模板,视图是XML)显示我的模型(mockdata)中的项目。
主要部分绑定到实体Interests
。详细信息部分从实体Messages
获取其信息。我有他们之间的参考约束,它的工作完全没问题。点击我的主要部分中的项目会在详细信息部分的表格中显示相应的项目。
主要部分列表:
<List
id="list"
items="{
path: '/InterestsSet',
sorter: {
path: 'InterestShortDescription',
descending: false
},
groupHeaderFactory: '.createGroupHeader'
}"
busyIndicatorDelay="{masterView>/delay}"
noDataText="{masterView>/noDataText}"
mode="{= ${device>/system/phone} ? 'None' : 'SingleSelectMaster'}"
growing="true"
growingScrollToLoad="true"
updateFinished="onUpdateFinished"
selectionChange="onSelectionChange">
<items>
<ObjectListItem
type="{= ${device>/system/phone} ? 'Active' : 'Inactive'}"
press="onSelectionChange"
title="{InterestShortDescription}"
number="{path :'MessagesSet', formatter:'.productCount'}">
</ObjectListItem>
</items>
</List>
Master部分需要显示一个数字值,该值等于实体Messages
中显示的项目总数(即等于详细信息部分中显示的行数)。经过一些研究(最终来自SAPUI5 - How to Bind Odata $count to a XML view),我开始了解formatter
属性并添加了它。
我的格式化程序如下:
productCount: function(oValue){
if (oValue) {
var sPath = this.getBindingContext().getPath() + '/MessagesID';
var oBindings = this.getModel().bindList(sPath);
return oBindings.getLength();
}
}
我尝试记录oValue
,但它似乎以undefined
的形式返回。
无论如何都要获取主列表中每个项目的计数。
答案 0 :(得分:1)
对于Master,InterestsSet的实体,假设Key属性为 InterestID 。
所以在你的代码中你有这个:
number="{path :'MessagesSet', formatter:'.productCount'}"
使用它:
number="{path :'InterestID', formatter:'.productCount'}"
现在,在控制器中, .productCount 功能应如下所示:
productCount: function(InterestID){
return this.getView().byId("idListInMessagesView").getItems().length;
}
或者这个:
productCount: function(InterestID){
uri = "/InterestSet(InterestID=' + InterestID + ')/YourNameNavigationsToMessages/$count";
return this.getView().getModel().read(uri);
}