我正在尝试这个示例,我必须添加总产品计数,即屏幕上显示的总表行数。
https://sapui5.netweaver.ondemand.com/sdk/explored.html#/sample/sap.m.sample.Table/preview
当我尝试访问 JSON 对象的长度时,即:
<headerToolbar>
<Toolbar>
<Label text="Products"></Label>
<Label text=""{ path: '/ProductCollection', formatter: 'sap.m.sample.Table.Formatter.totalFormatter' }""> </Label>
</Toolbar>
</headerToolbar>
totalFormatter:function(results) { return results.length; }
我收到 SAPUI5 未渲染错误:
未捕获类型错误:无法读取未定义的属性“长度”
我通过修改您的示例代码来回答您的问题。
<headerToolbar>
<Toolbar>
<Label text="Products"></Label>
<Label text=""
{
path: '/ProductCollection',
formatter: 'sap.m.sample.Table.Formatter.totalFormatter'
}"">
</Label>
</Toolbar>
</headerToolbar>
totalFormatter:function(results) {
return results.length;
}
然后您将获得表格的总行数。
基本思想是利用数据绑定的计算字段来获取结果长度。该文档可以在这里找到。