2012-08-27 85 views
0

我在這個網站上看到類似的問題,像我的,但我無法弄清楚我的代碼有什麼問題。我正在使用jquery自動完成,它的工作正常,除了該類別不顯示。我試着在Firebug的調試,但它看起來像我從來沒有「無功自我=這場」 _renderMenu內jQuery自動完成與遠程源和類別

$.widget("custom.catcomplete", $.ui.autocomplete, { 
    _renderMenu: function (ul, items) { 
     var self = this; 
     var currentCategory = ""; 
     $.each(items, function (index, item) { 
      if (item.category != currentCategory) { 
       ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>"); 
       currentCategory = item.category; 
      } 
      self._renderItem(ul, item); 
     }); 
    } 
}); 

$("#m_tSearchEngine").autocomplete({ 
    source: function (request, response) { 
     $.ajax({ 
      url: '../../Class/SearchEngine.asmx/GetSearchEngineItems', 
      data: "{ 'criteria': '" + $("#m_tSearchEngine").val() + "'}", 
      dataType: "json", 
      type: "POST", 
      contentType: "application/json; charset=utf-8", 
      success: function (data) { 
       var c = eval(data.d); 
       response($.map(c, function (item) { 
        return { 
         label: item.Name, 
         value: item.Name, 
         id: item.Id, 
         category: item.category, 
         subCategory: item.Type, 
         secondSubCategory: item.SecondType 
        } 
       })) 
      }, 
      error: function (XMLHttpRequest, textStatus, error) { 
       //alert(textStatus); 
      } 
     }); 
    }, 
    minLength: 1, 
    select: function (event, ui) { 
     location.href = "../../Literature/Pages/Literature.aspx?category=" + ui.item.category + "&subCategory=" + ui.item.subCategory + "&secondSubCategory=" + ui.item.secondSubCategory; 
    } 
}); 

這是我的JSON的樣子:

[{"category":1,"Id":49,"Name":"4800H","Type":7,"SecondType":0},{"category":1,"Id":86,"Name":"4900H","Type":7,"SecondType":0},{"category":2,"Id":1342,"Name":"D-DA1000HP-PSM(__)DBF","Type":25,"SecondType":54}] 

回答

1

我終於找到了我的問題。

而不是使用

$("#m_tSearchEngine").autocomplete 

的我不得不使用

$("#m_tSearchEngine").catcomplete