Javascript jQuery在选择填充其他字段时自动完成
我调用远程数据源并返回json。选择一个项目后,select:callback选项只允许我使用该项目的标签和值,但我还希望使用json对象的其他属性来自动填充其他字段 有没有一个方便的方法来做这件事,我错过了?到目前为止,我看到的选择是 全局缓存ajax响应json对象,并在选择后引用此全局对象 使用项目的值或标签在选择时重新查询数据库 对这两个都不是特别满意。想法 编辑 我忘了我用的是$.mapJavascript jQuery在选择填充其他字段时自动完成,javascript,jquery,json,jquery-ui,autocomplete,Javascript,Jquery,Json,Jquery Ui,Autocomplete,我调用远程数据源并返回json。选择一个项目后,select:callback选项只允许我使用该项目的标签和值,但我还希望使用json对象的其他属性来自动填充其他字段 有没有一个方便的方法来做这件事,我错过了?到目前为止,我看到的选择是 全局缓存ajax响应json对象,并在选择后引用此全局对象 使用项目的值或标签在选择时重新查询数据库 对这两个都不是特别满意。想法 编辑 我忘了我用的是$.map $('#accountName').autocomplete({ source: functi
$('#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");
});
是什么让你认为你只能使用标签和值
select: function (event, ui) {
foo = ui.item.label;
$("#bar").val(ui.item.id);
baz = (ui.item.JsonField);
}
是什么让你认为你只能使用标签和值
select: function (event, ui) {
foo = ui.item.label;
$("#bar").val(ui.item.id);
baz = (ui.item.JsonField);
}