我正在使用jquery自动完成pluguin。配置为使用多个值。minLength在jQuery自动完成多值插件
我设置选项的minLength:2
的minLength选项的工作只对第一个自动提示的话,多个值它不工作。
我如何配置或我需要重写以解决此问题的方法。
http://jqueryui.com/demos/autocomplete/#multiple
我正在使用jquery自动完成pluguin。配置为使用多个值。minLength在jQuery自动完成多值插件
我设置选项的minLength:2
的minLength选项的工作只对第一个自动提示的话,多个值它不工作。
我如何配置或我需要重写以解决此问题的方法。
http://jqueryui.com/demos/autocomplete/#multiple
的jQuery UI的网站上的多个远程演示演示此行为。你只需要添加自定义搜索功能:
$('#autocomplete').autocomplete({
search: function() {
// custom minLength
var term = extractLast(this.value);
if (term.length < 2) {
return false;
}
}
});
谢谢Chirstian Vargan。我得到了我的答案。 – minil 2012-04-09 02:38:07
我发现基督徒的版本从2012年非常有用的,但这里的其中在2016年(jQuery UI的1.12.0)工作的重新设计版本:
function split(val) {
return val.split(/\s+/);
}
function extractLast(term) {
return split(term).pop();
}
source: function(request, response) {
// delegate back to autocomplete, but extract the last term
const term = extractLast(request.term)
if (term.length < this.options.minLength) {
return false;
}
response($.ui.autocomplete.filter(
data, term));
}
的minLength
选项需要只是被提供为通常的,然后将所述source
函数内部中使用。如果需要更多上下文,请参阅演示。
所以...这里是你的代码?如果没有看到你在做什么,很难不可能帮助你。谢谢! – jmort253 2012-04-09 01:42:06