1
我想修改這個jQuery UI的示例來接受2維JSON數據。 http://jqueryui.com/demos/autocomplete/#remote-with-cachejQuery UI自動完成 - 在'source'中使用多維數組值,緩存示例
var cache = {}, lastXhr;
$("#birds").autocomplete({
minLength: 2,
source: function(request, response) {
var term = request.term;
if (term in cache) {
response(cache[ term ]);
return;
}
lastXhr = $.getJSON("search.php", request, function(data, status, xhr) {
cache[ term ] = data;
if (xhr === lastXhr) {
response(data);
}
});
}
});
我將如何修改此用 '名' 值在JSON數據是這樣的:
[{"name":"TEST1","slug":"blah-blah"},{"name":"TEST","slug":"example-slug-here"}]
謝謝。這工作。 – jwinn
對於任何引用此問題的用戶,如果第一次加載自動完成時出現問題,只有在刪除並重新輸入後,纔將最後一位更改爲此,因爲映射數據僅保存在緩存變量中: ' if(xhr === lastXhr){response(cache [term]); }' – jwinn