简体   繁体   English

SAPUI5筛选器仅适用于字符串

[英]SAPUI5 Filter works only with Strings

I want to filter my list by TypeID but my ID's are numbers (int32) and the "Contains" filter doesn't work with numbers, i think. 我想按TypeID过滤列表,但我的ID是数字(int32),我认为“包含”过滤器不适用于数字。

onSearch : function (oEvt) {
    var sQuery = oEvt.getSource().getValue();
    var list = this.getView().byId("myList");
    var binding = list.getBinding("items");         

    if (sQuery && sQuery.length > 0) {
        binding.filter( [ new sap.ui.model.Filter([
           new sap.ui.model.Filter("TypeID", sap.ui.model.FilterOperator.Contains, window.global.TypeID  )    //Error: request failed due to invalid system query options value!
        ],false)]);
    }
},

Any help? 有什么帮助吗?

From an OData perspective, the filter operation "Contains" is translated to OData operation "substring". 从OData角度来看,过滤器操作“包含”被转换为OData操作“子字符串”。 As the name of the operation already implies, it can only be used on strings. 正如该操作的名称已经暗示的那样,该操作只能在字符串上使用。 If you want to filter on non-strings, you will have to use the FilterOperator.EQ instead, but this doesn't allow you to filter on portions of the attribute. 如果要对非字符串进行过滤,则必须改用FilterOperator.EQ,但这不允许您对属性的某些部分进行过滤。

If you need to filter on portions of a numerical attribute, eg 23 to find 1234, you will have to apply client side filtering and build a routine that does the filtering for you. 如果需要对数字属性的某些部分进行过滤(例如,找到23才能找到1234),则必须应用客户端过滤并构建一个例程来为您执行过滤。

Instead of instantiating the filter using: 而不是使用以下方法实例化过滤器:

new Filter("TypeID", FilterOperator.Contains, typeID);

You will have to instantiate the filter using: 您将必须使用以下方法实例化过滤器:

new Filter("TypeID", fnTest);

Please do note that client side filtering may lead to enourmous amounts of data being pulled from the back-end. 请注意,客户端过滤可能会导致从后端提取大量数据。 So use it with caution. 因此,请谨慎使用。

Alternatively, you could of course also try to talk to the people in charge of the back-end logic, to see if they could redefine the search attribute as a string instead of a numerical value. 或者,您当然也可以尝试与负责后端逻辑的人员交谈,以查看他们是否可以将搜索属性重新定义为字符串而不是数字值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM