我调用远程数据源并返回json。选择项目后,select:
回调选项只允许我使用项目的标签和值,但我还想使用我的json对象的其他属性来自动填充其他字段。
有没有一种方便的方法可以做到这一点,我错过了?我到目前为止看到的选项是......
对这两者中的任何一个都不是特别满意。想法?
修改 我忘了我在使用$ .map
$('#accountName').autocomplete({
source: function (request, response) {
$.getAccountsByNameLike(request.term, function (data) {
response($.map(data, function (item) {
return {
label: item.Name + ' (' + item.Address.City + ', ' + item.Address.StateOrProvince + ')',
value: item.AccountId,
// Added to fix issue
raw: item
}
}));
}, function (error) {
// async kickoff a log to logging server service...
alert("There was a problem while trying to retrieve account names. Please contact support");
});
答案 0 :(得分:4)
是什么让你认为你只能使用标签和价值?
select: function (event, ui) {
foo = ui.item.label;
$("#bar").val(ui.item.id);
baz = (ui.item.JsonField);
}