我正在使用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