【发布时间】:2011-08-03 21:20:37
【问题描述】:
我计划为多个来源实现 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,如果我选择 b,则源应修改为 arrA;他源修改为arrB,依此类推。现在因为它将是一个多值自动完成,一旦我点击“,”源切换回 arrLookup。谁能帮我切换来源。我知道只能通过源来实现,但我无法获得正确的条件。
【问题讨论】:
-
我有点困惑。难道你不能把逻辑放在你的
source函数中以查看正确的数组吗? -
我试过了,但我无法获得这样做的逻辑。首先是我需要提取最后一个“,”之后的所有数据。然后我需要再次解析数据以切换数据源。我觉得有点复杂。虽然可行,但无法得到正确的条件。任何帮助将不胜感激。
标签: jquery autocomplete jquery-ui-autocomplete