我目前的代碼是使用jQuery 1.7.x.我想升級到jQuery 1.8,但我遇到了我的自動完成功能的問題。我用相同的代碼創建了2個jsfiddles。在一個例子中,它正常工作,而另一個則不正確。主要問題是當你搜索並點擊時,一個警告框應該顯示並說出被點擊的內容。它在舊的jQuery中工作,但不在1.8。jQuery 1.8自動完成類別問題
這裏是工作,1.7版本 - http://jsfiddle.net/u2GEe/1/
這裏是破碎的,1.8版本 - http://jsfiddle.net/TPWXh/3/
下面是代碼:
$.widget("custom.catcomplete", $.ui.autocomplete, {
_renderMenu: function(ul, items) {
var self = this,
currentCategory = "";
$.each(items, function(index, item) {
if (item.category != currentCategory) {
ul.append("<li class='ui-autocomplete-category search-dropdown-category'>" + item.category + "</li>");
currentCategory = item.category;
}
self._renderItem(ul, item);
});
}
});
$(document).ready(function() {
var data = [
{
label: "anders",
category: "aa"},
{
label: "andreas",
category: "aa"},
{
label: "antal",
category: "aa"},
{
label: "annhhx10",
category: "Products"},
{
label: "annk K12",
category: "Products"},
{
label: "annttop C13",
category: "Products"},
{
label: "anders andersson",
category: "People"},
{
label: "andreas andersson",
category: "People"},
{
label: "andreas johnson",
category: "People"}
];
$("#search_input").catcomplete({
source: data,
select: function(event, ui) {
alert(ui.item.label);
}
});
});
任何人都知道這筆交易是什麼?
「item:undefined」;/ – Stefan