首页 文章

如何在SAPUI5表中打印总表行

提问于
浏览
0

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

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

未捕获的TypeError:无法读取未定义的属性“长度”

1 回答

  • 0

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

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

    然后你将获得总表行 .

    基本思想是利用计算的数据字段绑定来获得结果长度 . 文档可以在here找到 .

相关问题