如何在SAPUI5表中打印总表行

问题描述 投票:0回答:1

我正在尝试这个示例,我必须添加总产品计数,即屏幕上显示的总表行数。

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 未渲染错误:

未捕获类型错误:无法读取未定义的属性“长度”

sapui5
1个回答
0
投票

我通过修改您的示例代码来回答您的问题。

  1. 编辑Table.view.xml,在工具栏中添加一个标签。
<headerToolbar>
    <Toolbar>
        <Label text="Products"></Label>
        <Label text=""
            {
                path: '/ProductCollection',
                formatter: 'sap.m.sample.Table.Formatter.totalFormatter'
            }"">
        </Label>
    </Toolbar>
</headerToolbar>
  1. 编辑formatter.js,添加一个方法totalFormatter。
totalFormatter:function(results) {
    return results.length;
}

然后您将获得表格的总行数。

基本思想是利用数据绑定的计算字段来获取结果长度。该文档可以在这里找到。

© www.soinside.com 2019 - 2024. All rights reserved.