0
我打算为多个源实现jquery-ui-autocomplete。以下是我的场景:我想根据某些条件拥有多个自动完成源。这里是我的代码:在运行时更改源代码自动完成
var arrLookup = ['a', 'b', 'c', 'd'];
var arrA = ['a1', 'a2', 'a3', 'a4'];
var arrB = ['b1', 'b2', 'b3', 'b4'];
var arrC = ['c1', 'c2', 'c3', 'c4'];
var arrD = ['d1', 'd2', 'd3', 'd4'];
$('#txt').autocomplete({
source: function (request, response) {
// delegate back to autocomplete, but extract the last term
response($.ui.autocomplete.filter(arrLookup, request.term.split(/,\s*/).pop()));
},
minLength: 1,
select: function (event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
this.value = terms.join(", ");
return false;
}
});
现在我想要的是,最初的自动完成源应该是arrLookup。如果我选择a,则应该将源修改为arrA,如果我选择b;他的源被修改为arrB,等等等等。现在,由于它将是一个多值自动完成功能,所以一旦我点击“”,源代码就会切换回arrLookup。任何人都可以帮我开源。我知道这只能通过源代码才能实现,但我无法获得正确的条件。
我有点困惑。难道你不能把逻辑放在你的'source'函数中去查看正确的数组吗? – 2011-04-12 13:12:45
我试过了,但我无法得到这样做的逻辑。首先,我需要提取最后一个“,”后的所有数据。然后我需要再次解析数据来切换数据源。我觉得有点复杂。虽然可行,但无法获得正确的条件。任何帮助,将不胜感激。 – Ashish 2011-04-12 13:26:56