jQuery自动完成“搜索"方法 [英] Jquery autocomplete "search" method

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

问题描述

我正在使用Jquery UI自动完成功能,这是下面的代码

I am using Jquery UI autocomplete, this is the code below


var opt_source = {...}
var options = {
            minLength: 0,
            source: opt_source,
            search: "aPreDefinedString"
        };
$(".searchable_input").autocomplete(options);

我的理解是,它现在应该搜索aPreDefinedString;这不会发生,而是在本地源中搜索userInput.有人可以指出我要去哪里了吗?

My understanding is that it should now search for aPreDefinedString ; This doesn't happen, rather it searches the local source for userInput. Could someone point out where I am going wrong?

推荐答案

好的,这就是我必须使其起作用的方式


var opt_source = {..};

var options = {
            minLength: 0,
            source: function(request, response){
                response(opt_source);
            }
        };
$(".searchable_input").autocomplete(options);

这似乎覆盖了内置搜索(我希望他们在将来的版本中不会破坏它)

This seems to override the inbuilt search (I hope they dont break it in future versions)

来自Jquery UI文档

From the Jquery UI documentation

第三个​​变体,即回调,提供了最大的灵活性,可用于将任何数据源连接到自动完成".回调有两个参数:

一个请求对象,具有一个称为"term"的单个属性,该属性引用文本输入中当前的值.例如,当用户在城市字段中输入"new yo"时,自动完成"字词将等于"new yo". 响应回调,它期望单个参数包含向用户建议的数据.

A request object, with a single property called "term", which refers to the value currently in the text input. For example, when the user entered "new yo" in a city field, the Autocomplete term will equal "new yo". A response callback, which expects a single argument to contain the data to suggest to the user.

该数据应根据提供的术语进行过滤,并且可以采用上述用于简单本地数据的任何格式(具有标签/值/两个属性的字符串数组或对象数组).提供自定义源回调以处理请求期间的错误时,这一点很重要.即使遇到错误,也必须始终调用响应回调.这样可以确保小部件始终具有正确的状态

这篇关于jQuery自动完成“搜索"方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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