2010-06-24 36 views
1

由於某種原因,jQuery UI的自動完成已停止爲我工作。我得到了與this webpage中描述的相同的錯誤。jQuery UI自動完成已停止工作

我從下面的網頁複製了查詢的內容,希望這裏的某個人能夠回答它。

謝謝!

我使用Jquery UI Autocomplete來獲取名稱列表。但由於某些原因,我得到一個錯誤:

alt text

$('#repName').removeAttr('readonly').focus(function() { 
        $(this).val(''); 
       }).autocomplete({ 
        source: function (request, response) { 
         tagId = $('#TagId').val(); 
         $.ajax({ 
          url: '/Developement/GetRepName', type: 'POST', dataType: 'json', 
          data: { searchText: request.term, maxResults: 10, tagId: tagId }, 
          success: function (data) { 
           response($.map(data, function (item) { 
            return { 
             label: item.Name, 
             value: item.RepId, 
             id: item.RepId 
            } 
           })) 
          } 
         }) 
        }, 
        select: function (event, ui) { 
         commissionAllicationModifications(ui.item.id, 0, 'A'); 
        } 
       }); 

我不知道爲什麼會這樣。 我正在使用Jquery UI 1.8.1。

我將不勝感激任何形式的幫助。

它來自jQuery UI 1.8.1文件,特別是jQuery UI Autocomplete 1.8.1。

.menu({ 
       focus: function (event, ui) { 
        var item = ui.item.data("item.autocomplete"); 
        if (false !== self._trigger("focus", null, { item: item })) { 
         // use value to match what will end up in the input, if it was a key event 
         if (/^key/.test(event.originalEvent.type)) { 
          self.element.val(item.value); 
         } 
        } 
       }, 
       selected: function (event, ui) { 
        var item = ui.item.data("item.autocomplete"); 
        if (false !== self._trigger("select", event, { item: item })) { 
         self.element.val(item.value); 
        } 
        self.close(event); 
        // only trigger when focus was lost (click on menu) 
        var previous = self.previous; 
        if (self.element[0] !== doc.activeElement) { 
         self.element.focus(); 
         self.previous = previous; 
        } 
        self.selectedItem = item; 
       }, 
*    blur: function (event, ui) { 
*     if (self.menu.element.is(":visible")) { 
*      self.element.val(self.term); 
*     } 
*    } 
      }) 
      .zIndex(this.element.zIndex() + 1) 
      // workaround for jQuery bug #5781 http://dev.jquery.com/ticket/5781 
      .css({ top: 0, left: 0 }) 
      .hide() 
      .data("menu"); 

雖然這是奇怪的,因爲這在另一個項目中完美地工作。我注意到當代碼碰到[starred]節時,self.menu節未定義。另外需要注意的是它甚至不發送請求。我在想這可能是我的焦點功能。

.focus(function() { 
    $(this).val(''); 

但事實並非如此。 謝謝你的幫助。

+0

您應該標記自己的答案作爲答案。另外,這種情況通常會因爲返回的數據沒有未引用的引號而中斷。 – tomdemuyt 2010-06-24 20:50:55

+0

我不確定我明白你的第二句話是什麼意思。 我一定會舉出我自己的答案,顯然我不能接受我自己的答案兩天。謝謝! – 2010-06-24 22:54:24

回答

3

事實證明,我包括一個定義$.fn.menu和這個造成的破壞的插件。我將其更改爲$.fn.fg_menu,問題已解決。

0

你使用的是什麼版本的jQuery核心?

我知道與visible detection有關的錯誤,並且與IE8有關。如果可能,你可以升級到測試機器上最新的jQuery,看看是否能解決你的問題?

如果你不喜歡升級,你也可以嘗試黑客的jQuery(太醜了!) - with this

if (self.menu.element.is(":visible"))

成爲

if (!(self.menu.element.css('display') == 'none'))

+0

感謝您的回答!我正在使用jQuery 1.4.2。事實證明,這不是我的問題,但希望它會幫助別人! – 2010-06-24 20:48:02