具有过滤器的批量GET的UI5 OData服务

时间:2016-09-15 14:02:34

标签: odata sapui5

我有一个OData模型,我需要进行批量读取请求 模型如下所示

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);
        });

过滤器和批处理请求创建如下

Wait()

当我们调试ABAP代码时,我们没有得到过滤器。

1 个答案:

答案 0 :(得分:3)

filters不是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){
    }
});
相关问题