Why my filter is not working in v2.ODataModel “read”?

前端 未结 3 893
太阳男子
太阳男子 2020-12-07 05:19

I am using the OData model to read data. But it doesn\'t work. Check the code below:

getGuid: function(pernr) {
  var          


        
相关标签:
3条回答
  • 2020-12-07 05:38
    1. Check if your OData service supports the $filter query in the first place.
    2. Use the read method correctly:
      myV2ODataModel.read("/PersonalDetailSet"/* No $filter queries here! */, {
        filters: [ // <-- Should be an array, not a Filter instance!
          new Filter({ // required from "sap/ui/model/Filter"
            path: "myField",
            operator: FilterOperator.EQ, // required from "sap/ui/model/FilterOperator"
            value1: "..."
          })
        ],
        // ...
      });
    • API reference: sap.ui.model.odata.v2.ODataModel#read
    • API reference: sap.ui.model.Filter
    0 讨论(0)
  • 2020-12-07 05:41

    If you want to apply additional URL Parameters in the read function you have to do this via the "urlParameters" parameter:

    getGuid: function(pernr){
        var self = this;
        var url = "/PersonalDetailSet";
        self.setBusy(true);
        this.oModel.read(url, {
            urlParameters: {
                "$filter" : "Pernr eq '00000001'"
            },
            success: function(res){
                self.setBusy(false);
                self.guid = res.results[0].Guid;
            },
            error: function() {
                self.setBusy(false);
            }
        });
    }
    
    0 讨论(0)
  • 2020-12-07 05:43

    First you check whether you are getting model in the scope or not. As i can see this.oModel which is not proper way of getting model. Better use this.getModel() or this.getView().getModel() and then check the call. Passing filter is not the right way but still it should work.

    0 讨论(0)
提交回复
热议问题