2016-09-15 56 views
0

我有一個OData的模型,我需要進行批量讀取請求 的模型ctreated如下UI5 OData服務與一批GET與過濾器

this.oModel = new sap.ui.model.odata.ODataModel(sURI,{ 
       json  : true, 
       user  : "<username>", 
       password : "<password>", 
       useBatch : true 
     }); 

過濾器和批次要求如下創建

var allfilters = [new sap.ui.model.Filter({ 
       path:'filter1', 
       operator : sap.ui.model.FilterOperator.EQ, 
       value1 : this.filter1value 
      }), 
      new sap.ui.model.Filter({ 
       path:'DateField', 
       operator : sap.ui.model.FilterOperator.EQ, 
       value1 : 'SCHED' 
      }), 
      new sap.ui.model.Filter({ 
       path:'StartDate', 
       operator : sap.ui.model.FilterOperator.EQ, 
       value1 : oDateFormat.format(this.startDate.toDate()) 
      }), 
      new sap.ui.model.Filter({ 
       path:'EndDate', 
       operator : sap.ui.model.FilterOperator.EQ, 
       value1 : oDateFormat.format(this.endDate.toDate()) 
      })]; 

     var batchrequest = this.oModel.createBatchOperation('/ReadEntitySet','GET',{ 
      filters : allfilters 
     }); 
     this.oModel.addBatchReadOperations([batchrequest]); 
     this.oModel.submitBatch(this._gotData.bind(this),function(err){ 
      console.log(err); 
     }); 

當我們調試ABAP代碼時,我們沒有得到過濾器。

回答

2

過濾器不是createBatchOperation的oData參數的有效屬性。您可以通過將$ filter直接附加到您的路徑來實現此目的,也可以使用v2 ODataModel,示例如下:

this.oModel = new sap.ui.model.odata.v2.ODataModel(sURI,{ 
      json  : true, 
      user  : "<username>", 
      password : "<password>", 
      useBatch : true 
}); 

this.oModel.setDeferredGroups(["myDeferredGroup"]); 

this.oModel.read("/ReadEntitySet",{ 
    groupId: "myDeferredGroup", 
    filters: allFilters, 
    success: this._gotData.bind(this), 
    error : function(err){ 
     console.log(err); 
    } 
}); 

this.oModel.submitChanges({ 
    groupId: "myDeferredGroup", 
    success: function(oData){ 

    }, 
    error : function(err){ 
    } 
});