使用过滤器调用.read时“无法读取未定义的属性sPath”

时间:2017-09-22 13:59:02

标签: sapui5

我想从SAPUI5执行带过滤器的OData Get请求。 OData URL如下所示:

  

/ sap / opu / odata / MAT_SRV / Get_MATSet?$ filter =(Plant eq'AlHG')和(MaterialType eq'PS01')和((MaterialNumber eq'61345280')或(MaterialNumber eq'61345280'))

在这里,我已经为OData服务(下例中的oDataFilter)创建了过滤器数组,如下所示:

var oPlant = new Filter("Plant", FilterOperator.EQ, "A1HG");
var oPlantFilter = new Filter({
  filters: [oPlant],
  and: true
});
var oMatType = new Filter("MaterialType", FilterOperator.EQ, "PS01");
var oMatTypeFilter = new Filter({
  filters: [oMatType],
  and: true
});
var oMaterialNumberFilter = this._getMatNumbers(); //GET ALL MATERIAL NUMBER FILTERS SEPERATED By OR
var oDataFilter = new Filter({
  filters: [
    oPlantFilter,
    oMatTypeFilter,
    oMaterialNumberFilter
  ],
  and: true
});
BackEndModel.read("/Get_MATSet", {
  filters: oDataFilter,
  success: jQuery.proxy(this.fSuccess, this),
  error: jQuery.proxy(this.fError, this)
});
 
_getMatNumbers: function() {
  var aTokens = this.byId("Mat_MultiInput").getTokens(); //ITERATE THROUGH EACH VALUES ENTERED BY USER
  var aMatFilter = [];
  for (var i in aTokens) {
    aMatFilter.push(new Filter("MaterialNumber", FilterOperator.EQ, aTokens[i].getKey()));
  }
  var oFilter = new Filter({ filters: aMatFilter, and: false });
  return oFilter;
}

但是,执行时出现以下错误:

  

无法读取未定义的属性sPath。

有人可以告诉我这里我做错了什么吗?或者引导过滤器表达式传递给OData服务,该服务对应于OData URL中提到的过滤器值?

2 个答案:

答案 0 :(得分:1)

我用过滤器查找了我的一个编码,发现“我的”oDataFilter是一个数组。所以试试这个:

for /?

答案 1 :(得分:0)

由于 oPlantFilter oMatTypeFilter 只包含一个过滤条件,ypu可以直接在 oDataFilter 中使用它们,如下所示。我希望它能帮助你解决问题。还有一件事情集中在路径属性名称及其数据类型

var oPlantFilter = new sap.ui.model.Filter("Plant", sap.ui.model.FilterOperator.EQ, 'A1HG');
var oMatTypeFilter = new sap.ui.model.Filter("MaterialType", sap.ui.model.FilterOperator.EQ, 'PS01');
var oMaterialNumberFilter = this._getMatNumbers();

var oDataFilter = new sap.ui.model.Filter({ 
    filters: [oPlantFilter, oMatTypeFilter, oMaterialNumberFilter], 
    and: true 
});

BackEndModel.read( "/Get_MATSet", {
    filters: oDataFilter,
    success: jQuery.proxy(this.fSuccess, this),
    error: jQuery.proxy(this.fError, this) 
});

_getMatNumbers: function() {
    var aTokens = this.byId("Mat_MultiInput").getTokens();
    var aMatFilter = [];
    for (var i in aTokens) {
        aMatFilter.push(new sap.ui.model.Filter("MaterialNumber", sap.ui.model.FilterOperator.EQ, aTokens[i].getKey())); 
    }
    var oFilter = new sap.ui.model.Filter({ 
        filters: aMatFilter, 
        and: false
    });
    return oFilter;
}