JQuery 自动完成自定义查找功能 [英] JQuery Autocomplete Custom Lookup Function
问题描述
我想在我的表单中使用 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屋!