1
以下jQuery正在成功運行。我正在嘗試的是按Id
進行搜索。更具體。我想通過Name
或Id
進行搜索。 有什麼建議嗎?無法用兩個變量返回obj
$(function() {
$("#KUNDE").focus();
});
var uri = 'json.json';
function find() {
var info = $('#KUNDE').val();
$.getJSON(uri).done(function(data) {
var item = data.filter(function(obj) {
return obj.name === info;
//return obj.name,ID === info;
//return { obj: name, obj:ID } === info;
//return ['ID', 'name'] == info;
})[0];
if (typeof item !== 'undefined' || item !== null) {
$("ul").append("<li>" + 'ID = ' + item.ID, 'Name = ' + item.name, "<br />" + 'Phone = ' + item.phone, "<br />" + 'Contact = ' + item.contact, "<br />" + 'BalanceLCY = ' + item.balanceLCY, "<br />" + 'CreditLimitLCY = ' + item.creditLimitLCY, "</li>")
}
}).fail(function(jqXHR, textStatus, err) {
$('#RESULTS').text('Error: ' + err);
});
}
var options = {
url: "json.json",
getValue: "name",
list: {
match: {
enabled: true
}
},
theme: "square"
};
$("#KUNDE").easyAutocomplete(options);
看到:HTTP://easyautocomplete.com/guide#sec-categories – madalinivascu