2012-01-12 26 views
6

所以我搜索,但無法找到答案。這可能是微不足道的,但我不明白是什麼導致了這一點。jQuery UI自動填充不過濾數據

我正在使用jQuery UI Autocomplete,它顯示json結果。所以我知道我的JSON是有效的。但是,它不會過濾任何東西。所以我可以輸入一個數字,它只顯示所有的數據。任何提示將非常感激!

我很感謝你的時間!

這是我的自動完成代碼。

$.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">' + item.category + '</li>'); 
       currentCategory = item.category; 
      } 
      self._renderItem(ul, item); 
     }); 
    } 
    }); 


    $('#category').catcomplete({ 
    source: function(request, response) { 
     $.ajax({ 
      url: '/wp-content/plugins/pagelines-sections/searchbar/products.json', 
      dataType: 'json', 
      data: { 
       term: request.term 
      }, 
      cache: true, 
      success: function(data) { 
       response($.map(data.products, function(item) { 
        return { 
         category: item.category, 
         label: item.label, 
         value: item.value 
        }; 
       })); 
      } 
     }); 
     }, 
     minLength: 1 
    }); 

回答

2

過濾必須根據「期限」參數來進行服務器端。使用Firebug或Chrome開發人員工具(F12)檢查服務器返回的數據,並確保它取決於「term」參數。