How to concatenate two sap.ui.model.Filter in JSON model?

匿名 (未验证) 提交于 2019-12-03 10:10:24

问题:

I have a JSON model like this:

{     "VEHICLES": [         {             "vehicleId": "0001",             "routeName": "Ginza Line"         },         {             "vehicleId": "0002"             "routeName": "Another Line"         } }

I am implementing a sort function like this:

onSearch : function (oEvent) {     var sQuery = oEvent.getParameter("query");      if (sQuery) {         var oFilter1 = new Filter("vehicleId", function(value) {             return value.includes("sQuery");         });          var oFilter2 = new Filter("routeName", function(value) {             return value.includes("sQuery");         });          var allFilter = new Filter([oFilter1, oFilter2], false});         var list = this.getView().byId("masterList");         list.getBinding("items").filter(allFilter);     }  }

When I input "000" in search field, I am expecting to return both data items, but it returns none. Why?

I have tried single "vehicleId" filter, it worked.

I have also tried

var allFilter = new Filter({     filters: [oFilter1, oFilter2],      and: false  //OR });

But allFilter.bAnd returned undefined, I am confused.

Ref:

https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.Filter.html

https://openui5.hana.ondemand.com/#docs/guide/96804e3315ff440aa0a50fd290805116.html#loio50357d719b35439984348080bcbb14a4

https://github.com/SAP/openui5/issues/1442

回答1:

There is a small mistake. You are checking if the vehicleId includes the string "sQuery". Remove the quotes around sQuery and the filters will work fine.

value.includes(sQuery);


回答2:

Thanks to @boghyon and @suryabhan mourya, I changed the fnTest function to

var oFilter1 = new Filter("vehicleId", function(value) {     return value.includes(sQuery.toUpperCase()); });

and it's working!



回答3:

Update:

according to API document. Put the parameter to Array

list.getBinding("items").filter([allFilter]);

@boghyon found from the source code here that it is actually got converted to Array



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!