根据文档,我可以为 Kendo 自动完成控制设置“startswith”、“contains”或“endswith”过滤器:
The filtering method used to determine the suggestions for the current value. The default filter is "startswith" - all data items which begin with the current widget value are displayed in the suggestion popup. The supported filter values are startswith, endswith and contains.
有什么方法可以设置我自己的过滤逻辑吗?或者至少对结果进行排序的方法?我需要的是一个“包含”过滤器,其中使用我自己的逻辑根据与查询的相关性对结果进行排序。
最佳答案
您必须使用sort.compare
属性来实现这一点,例如:
sort: {
field: "FieldName",
dir: "asc",
compare: function(a, b) {
return a.Relevancy > b.Relevancy;
}
}
Demo .
注意:当您定义 compare
时,它似乎忽略了属性 field
和 dir
,但您需要 来定义它,否则它也会忽略 compare
属性。
关于javascript - Kendo Autocomplete 中的自定义过滤/排序逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43743726/