我正在尝试将值作为 Autocomplete jQuery 方法获取,并将选定的输入值存储到文本框中(推送到文本框)。听起来很简单,但这个 JSON 模式有点花时间。
我可以在这里获得快速帮助吗?
jQuery代码:
$("#material_number").autocomplete({
source: function (request, response) {
$.ajax({
url: "http://ws.geonames.org/searchJSON",
dataType: "json",
data: {
style: "full",
maxRows: 12,
name_startsWith: request.term
},
success: function (data) {
response($.map(data.geonames, function (item) {
return {
// following property gets displayed in drop down
label: item.name + ", " + item.countryName,
// following property gets entered in the textbox
value: item.name,
// following property is added for our own use
my_description: item.fcodeName
}
}));
}
});