jQuery自动完成(devbridge)从头开始搜索 [英] jQuery autocomplete (devbridge) search from beginning

查看:105
本文介绍了jQuery自动完成(devbridge)从头开始搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用devbridge的自动完成jQuery脚本。
是否可以选择从单词的开头过滤搜索而不是应用于单词的任何位置?

I am using devbridge's autocomplete jQuery script. Is there an option to filter the search from the beginning of the word and not to apply to anywhere in a word?

如果我输入R 那么我想只看到以R开头的单词,而不是每个单词中的R字符。

Like if I would type "R" then I would like to see only the words starting with R and not the R character in every word.

基本上从开头的过滤器搜索是我正在寻找的for。

Basicly a search from beginning kind of filter is what I am looking for.

怎么可能这样做?有没有这个选项?

How could this be done? Is there an option for this?

<script>
$(function() {

var fruits = [
   { value: 'Apple',  data: 'Apple' },
   { value: 'Pear',   data: 'Pear' },
   { value: 'Carrot', data: 'Carrot' },
   { value: 'Cherry', data: 'Cherry' },
   { value: 'Banana', data: 'Banana' },
   { value: 'Radish', data: 'Radish' }
];

  $("#autocomplete").autocomplete({
        lookup: fruits,
        onSelect: function (suggestion) {
          alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
        },
  });
});
</script>


推荐答案

添加lookupFilter函数:

Add lookupFilter function:

$("#autocomplete").autocomplete({
    lookup: fruits,
    onSelect: function (suggestion) {
      alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
    },
    lookupFilter: function (suggestion, query, queryLowerCase) {
        return suggestion.value.toLowerCase().indexOf(queryLowerCase) === 0;
    }
});

这篇关于jQuery自动完成(devbridge)从头开始搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆