Ui5 doc提供了一个示例,用于将过滤器列表与AND或OR组合:
new sap.ui.model.Filter({
filters: [...],
and: true|false
})
我有两个与OR连接的过滤器数组,如何将这两个数组连接到ALL ?像这样:
产品?$ skip = 0& $ top = 20& $ filter =(substringof('One way',ID)或 substringof('单向',类型)和 substringof('A',Name)或Direction eq 'A'
以下是我的代码:
oTableSearchState1 = [new Filter(filterArray1, false)] //OR
oTableSearchState2 = [new Filter(filterArray2, false)] //OR
oTable.getBinding("items").filter(oTableSearchState1, "Application");
(我已尝试过new Filter(filterArray1.concat(filterArray2), false);
和oTable.getBinding("items").filter(oTableSearchState1, "Application").filter(oTableSearchState2, "Application")
,但显然它们无效。)
答案 0 :(得分:1)
对于需要执行这些复杂操作的情况,可以使用嵌套过滤。您可以使用过滤器中的过滤器来执行此类操作。
以下是基于您的问题的示例过滤器:
var oFilter = new Filter({
filters: [
new Filter({
filters:[
new Filter("ID", FilterOperator.Contains, "One way"),
new Filter("Type", FilterOperator.Contains, "One way")
],
and : false
}),
new Filter({
filters:[
new Filter("Name", FilterOperator.Contains, 'A'),
new Filter("Direction", FilterOperator.EQ, "A")
],
and : false
})
],
and: true
});