SAPUI5过滤多个参数并对其进行操作

时间:2016-10-06 12:44:40

标签: filter binding sapui5 operation

我想在表绑定上搜索实现多个过滤器。要求是将多个过滤器与和条件相关联:

伪代码:

if(filterA && filter1 || filterB && filter1 || filterC && filter1 ){...}

我怎样才能实现它?

我尝试了以下内容:

var filter1 = [ new sap.ui.model.Filter("desc", FilterOperator.Contains, sQuery), new sap.ui.model.Filter("flag", FilterOperator.NE, 'X')];
                var filter2 = [ new sap.ui.model.Filter("costnr", FilterOperator.Contains, sQuery), new sap.ui.model.Filter("flag", FilterOperator.NE, 'X')];
                var filter3 = [ new sap.ui.model.Filter("location", FilterOperator.Contains, sQuery), new sap.ui.model.Filter("flag", FilterOperator.NE, 'X')];
                var filter4 = [ new sap.ui.model.Filter("location2", FilterOperator.Contains, sQuery), new sap.ui.model.Filter("flag", FilterOperator.NE, 'X')];
                var filter5 = [ new sap.ui.model.Filter("street", FilterOperator.Contains, sQuery), new sap.ui.model.Filter("flag", FilterOperator.NE, 'X')];
                var filter6 = [ new sap.ui.model.Filter("houseno", FilterOperator.Contains, sQuery), new sap.ui.model.Filter("flag", FilterOperator.NE, 'X')];
                var filter7 = [ new sap.ui.model.Filter("customer", FilterOperator.Contains, sQuery), new sap.ui.model.Filter("flag", FilterOperator.NE, 'X')];
                var filter8 = [ new sap.ui.model.Filter("ordernr", FilterOperator.Contains, sQuery), new sap.ui.model.Filter("flaga", FilterOperator.NE, 'X')];
                var oFilterExt = new sap.ui.model.Filter({filters: [filter1,filter2, filter3, filter4, filter5, filter6, filter7, filter8], and: false}); 

                //binding
                binding.filter(oFilterExt, sap.ui.model.FilterType.Application);

1 个答案:

答案 0 :(得分:3)

您使用$lookup属性进入了正确的轨道:

new sap.ui.model.Filter({ 
   and:false, 
   filters: [
      new sap.ui.model.Filter({
         and: true,
         filters: [
            new sap.ui.model.Filter("property1", FilterOperator.Contains, sQuery),
            new sap.ui.model.Filter("property2", FilterOperator.Contains, sQuery)
         ]}),
      new sap.ui.model.Filter({
         and: true,
         filters: [
            new sap.ui.model.Filter("property3", FilterOperator.Contains, sQuery),
            new sap.ui.model.Filter("property4", FilterOperator.Contains, sQuery)
         ]}),
      new sap.ui.model.Filter({
         and: true,
         filters: [
            new sap.ui.model.Filter("property5", FilterOperator.Contains, sQuery),
            new sap.ui.model.Filter("property6", FilterOperator.Contains, sQuery)
         ]})
   ]});