加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

SAPUI5 – 如何将Odata $count绑定到XML视图

发布时间:2020-12-16 07:41:04 所属栏目:百科 来源:网络整理
导读:可能这是一个基本的问题,但是我在 XML视图中绑定了Odata计数时遇到麻烦. 在下面的例子中,我想绑定来自Odata模型的产品计数. List items="{/Categories}"} ObjectListItem title="{CategoryName}" number="{path : 'Products/$count'}" numberUnit="Products"
可能这是一个基本的问题,但是我在 XML视图中绑定了Odata计数时遇到麻烦.

在下面的例子中,我想绑定来自Odata模型的产品计数.

<List items="{/Categories}"} >  
<ObjectListItem 
    title="{CategoryName}"
    number="{path : 'Products/$count'}"
    numberUnit="Products" 
</ObjectListItem>
</List>

每个类别需要显示相应类别中的产品数量…..如

/Categories(1)/Products/$count
/Categories(2)/Products/$count

感谢您的帮助提前.

我不认为它目前是可能的
– $count是一个OData查询选项,ODataListBinding中的等效项是length,例如Products.length我不能想到一种绑定到它的方法

您可以使用格式化程序以几种方式实现计数

选项1 – 最简单的,创建一个列表绑定,它读取总数量的产品,它进行同步调用,并只返回$count

function productCount(oValue) {
    //return the number of products linked to Category // sync call only to get $count
    if (oValue) {
        var sPath = this.getBindingContext().getPath() + '/Products';
        var oBindings = this.getModel().bindList(sPath);
        return oBindings.getLength();
    }
};

<List items="{/Categories}"} >  
 <ObjectListItem 
    title="{CategoryName}"
    number="{path : 'CategoryName',formatter:'productCount'}"
    numberUnit="Products" 
 </ObjectListItem>
</List>

选项2 – 使用展开并返回一个非常小的数据集,在这种情况下只有CategoryName和ProductID,这里需要注意的是您是否必须通过表分页获取完整列表

function productCount(oValue) {
    //read the number of products returned
    if (oValue) {
        return oValue.length;
    }
};

<List items="{/Categories,parameters:{expand:'Products',select:'CategoryName,Products/ProductID'}}">  
 <ObjectListItem 
    title="{CategoryName}"
    number="{path : 'Products',formatter:'productCount'}"
    numberUnit="Products" 
 </ObjectListItem>
</List>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读