【发布时间】:2013-05-31 15:50:34
【问题描述】:
您好,我遇到了更改事件的问题。 通过文档应该有对象 ui.item
选择一个项目后; ui.item 是指选中的项目。总是在关闭事件之后触发。
但是当我尝试它时 ui.item 是未定义的 :( 当自动完成中的输入与脚本中的数据不匹配时,我想取消设置 s_town_id。
<input id="s_town" type="text" name="s_town" />
<input type="text" id="s_town_id" name="s_town_id" />
$(function() {
$("#s_town").autocomplete({
source: function(request, response) {
$.ajax({
url: "/_system/_ajax/uiautocomplete.php",
dataType: "json",
data: {
name: "s_town",
term: request.term
},
success: function(data) {
response($.map(data, function(item) {
return {
label: item.whisper_name+ " [" + item.zip_code + " / " + item.lup_state + "]",
value: item.whisper_name,
id: item.whisper_id,
zip_code: item.zip_code,
lup_state: item.lup_state,
stateid: item.stateid
}
}))
}
})
},
minLength: 2,
select: function(event, ui) {
$("#s_town_id").val(ui.item.id);
},
change: function(event, ui)
{
// ui.item is undefined :( where is the problem?
$("#s_town_id").val(ui.item.id);
}
});
});
【问题讨论】:
-
嘿 Stenly,我遇到了完全相同的问题,并且不得不使用相同的解决方法。您能找到更好的解决方案吗?
-
hmm 意识到问题在于我从教程中加载了源代码,该教程的 ui 版本为 1.8,对于最终遇到此问题的任何人,此问题已在 1.8.11 中修复。 bugs.jqueryui.com/ticket/5490