0
在那里我有一个单词列表我使用这个版本的jQuery的自动完成:jQuery的自动完成匹配无序多个单词
$(function() {
var availableTags = [
"hello world", "foo bar", "bar foo world", "hello", "bar"
];
function customFilter(array, terms) {
arrayOfTerms = terms.split(" ");
var term = $.map(arrayOfTerms, function (tm) {
return $.ui.autocomplete.escapeRegex(tm);
}).join('|');
var matcher = new RegExp("\\b" + term, "i");
return $.grep(array, function (value) {
return matcher.test(value.label || value.value || value);
});
};
$("#tags").autocomplete({
source: availableTags,
multiple: false,
mustMatch: false
,source: function (request, response) {
// delegate back to autocomplete, but extract the last term
response(customFilter(
availableTags, request.term));
},
});
});
“世界你好”,“富巴” ,“bar foo world”,“hello”,“bar”
我的问题是,例如在输入“world hello”时,我想只显示“hello world”。
此外,当我键入一个空格,所有选项都显示在我的情况是不正确的。
我该如何实现这种行为?
谢谢