jQuery自动完成自定义查找功能 [英] JQuery Autocomplete Custom Lookup Function

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

问题描述

我想使用jquery.autocomplete.js插件输入表单.我想在客户端搜索,不能使用ajax.但是我不希望在数组中使用一些简单的基于包含"的搜索算法.我想做的是在javascript中编写一个自定义搜索功能,以搜索和排序结果.这甚至有可能吗?

I want to use jquery.autocomplete.js plugin for an input in my form. I want to search on the client side and can't use ajax. But I don't want some simple "Contains"-based search algorithm within an array. What I want to do is to write a custom search function in javascript to search and order the results. Is this even possible and how?

感谢您的时间.

推荐答案

肯定是.您将 source 指定为将回答字符串列表或 {label,value} 对象的函数.

It surely is. You specify source to be a function which will answer a list of strings or alternatively {label, value} objects.

$('#myInput').autocomplete({
    source: function (request, response) {
        var term = request.term;
        var data = handleAutocomplete( term);  /* get answers from somewhere.. */
        response( data);
    }
});

function handleAutocomplete (term) {
    var options = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"];
    // use 'term' for custom filtering etc.
    return options;
}

请参阅: http://api.jqueryui.com/autocomplete/#option-source

这篇关于jQuery自动完成自定义查找功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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