我有一個jQuery自動完成,並且select
事件永遠不會被解僱。jQuery的ui自動完成沒有發射選擇事件
腳本是這樣的:
$(function() {
$('#AppName').autocomplete({
minLength: 0,
source: function(request, response) {
var url = "/api/AddAppAjax";
$.getJSON(url, { term: request.term }, function(data) {
response(data);
})
},
select: function (event, ui) {
alert(ui.item.id); <---- !This is never hit!
$('#selected-id').val(ui.item.id);
}
});
})
在Web API控制器動作看起來是這樣的:
public IEnumerable<object> Get(string term)
{
var appManager = new AppManager();
var appList = appManager.GetAllApps().AsQueryable().ToList();
var appListJson = from fbApp in appList
select new
{
id = App.Id,
value = App.AppName,
label = App.ToString()
};
return appListJson;
}
自動完成本身工作正常。只是沒有開火的事件。我嘗試用bind
和on
來綁定事件,這也沒有幫助。我也在change
事件中嘗試了這一點,但這也不會被解僱,或者它對我來說也是如此。我無法弄清楚爲什麼事件沒有解僱。
難道是jQuery 1.9.1的問題?這裏是[問題的鏈接](https://forum.jquery.com/topic/autocomplete-click-to-select-item-not-working-in-1-9-1) – AVK
對不起,我忘了提及...我正在使用jQuery 2.1.1和jQuery ui 1.10.4 –