和/或Filter Array之间

问题描述 投票:0回答:1

所以我有两个过滤器数组,而不是只是简化并让UI5用和/或运算符选择/分组相应的属性,我想在两个过滤器数组之间执行AND。

我尝试传递两个过滤器数组,并添加和。但它不起作用。

var kFilter = new Filter({
  filters: [
    dFilters,
    bFilters
  ],
  and: true
});
javascript sapui5 ui5-library
1个回答
1
投票
var aFilter = [];
var aOrFilter = [];
var aAndFilter = [];

//Create filter array for OR condition
aOrFilter[
    new sap.ui.model.Filter("Property1", sap.ui.model.FilterOperator.EQ, sValue),
    new sap.ui.model.Filter("Property2", sap.ui.model.FilterOperator.EQ, sValue)
];

//Create filter array for AND condition
aAndFilter[
  new sap.ui.model.Filter("Property3", sap.ui.model.FilterOperator.EQ, sValue),
  new sap.ui.model.Filter("Property4", sap.ui.model.FilterOperator.EQ, sValue)
];

//Concatinating both filter arrays with AND condition
aFilter = new sap.ui.model.Filter([
    new sap.ui.model.Filter(aOrFilter, false), //Filters get OR codition
    new sap.ui.model.Filter(aAndFilter, true) //Filters get AND condition
], true); //Concatinating both with AND condition

结果:

(Property1 EQ "XXX" OR Property2 EQ "XXX") AND (Property3 EQ "XXX" AND Property4 EQ "XXX")