How to Bind OData $count from expanded collection in an XML view

后端 未结 4 621
终归单人心
终归单人心 2020-12-30 05:30

May be this is a basic question, but I have trouble binding the OData count in XML view.

In the following example, I want to bind the count of products from the ODat

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-30 06:04

    I dont think its currently possible - $count is an OData query option, the equivalent in ODataListBinding is length, eg Products.length I cant think of a way to bind to it

    you can achieve the count in a couple of ways using a formatter

    option 1 - the simplest, create a list binding which reads the total number of products, it does a synchronous call and returns only the $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();
        }
    };
    
      
     
    
    

    option 2 - use an expand and return a very small set of data, in this case only CategoryName and ProductID, the caveat here is whether you have to by pass table paging to get full list

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

提交回复
热议问题