我正在使用 Spring MVC 进行自动完成(jquery)。我已经完成了一切,数据在自动完成中正确显示,但属性不显示 onfocus 事件。每当我在 onfocus 方法中调用“ui.item.username”时,它总是显示空值。
$( "#city" ).autocomplete({
minLength: 0,
source: function( request, response ) {
$.ajax({
url: "person.ajax",
dataType: "json",
data: {
maxRows: 6,
startsWith: request.term
},
success: function( data ) {
response( $.map( data.zipcodes, function( item) {
return {
label: item.realName + item.realName,
value: item.username
}
}));
}
});
},
直到这里它工作正常但是当我在 onfocus 方法中调用属性(在以下方法中)时,它在焦点事件(jquery)中显示我为 null
focus: function(event, ui) {
alert($( event.target ).val(ui.item.ealName)); // it displays me null value at this point
},
select: function( event, ui ) {
}
有什么建议吗?