有了这个代码:问题与jQuery ui`s自动完成选择回调(1.8)
function setupRow(event, ui) {
var textbox, // how do i get to the textbox that triggered this? from there
// on i can find these neighbours:
hiddenField = textbox.next(),
select = textbox.parents('tr').find('select');
textbox.val(ui.item.Name);
hiddenField.val(ui.item.Id);
$.each(ui.item.Uoms, function(i, item){
select.append($('<option>' + item + '</option>'));
});
return false;
}
function setupAutoComplete(){
var serviceUrl = "/inventory/items/suggest";
$("input.inputInvItemName").autocomplete({
source: function(request, response) {
$.ajax({
url: serviceUrl,
data: request,
dataType: "json",
success: function(data) {
response($.map(data.InventoryItems, function(item) {
return {
value: item.Name
};
}));
},
select: function(event, ui) {
setupRow(event, ui);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
},
minLength: 3,
delay: 500
});
}
一切似乎确定。问题是select处理程序永远不会触发,即使是为了调试目的而封装我的原始代理setupRow的匿名函数也不会被调用。
任何人都可以看到我的错误?
我也在评论中留下了一个问题:我如何到达有自我暗示的文本框。在这里不能使用id,因为这些文本框是多个并且交互地动态生成。还是有另一种方式来做同样的事情?
感谢您的帮助!
你忘了放;在ajax声明结束时。 – Kai 2010-07-01 04:15:02
我不这么认为...... 你需要向下滚动一下。 – Jan 2010-07-01 04:23:02
sry ..我的意思是..在成功处理程序的声明结束.. – Kai 2010-07-01 04:28:26