2015-03-25 61 views
0

我正在使用angular-ui select2指令。我知道它現在已被棄用,但我的應用程序始終都在使用此指令,並且我想要改進該指令。不過,我們將遷移到新的ui = select替代方案。Angular-UI Select2指令搜索功能不起作用

我正在按照這裏的示例通過ajax調用加載json數據http://select2.github.io/select2/。數據加載正確,可以選擇,但我無法搜索和縮小/篩選結果。根據我的理解,這在指令中得到了支持。當我鍵入內容時,數據刷新但不會根據搜索條件進行過濾。下面是我的代碼

<input type="text" id="users" ui-select2="filters.select2Test" ng-model="filters.model.users" 
data-placeholder="Pick a user" ng-required="true" style="width: 300px" /> 

$scope.filters = { 
        select2Test: { 
        id: function(user) { 
         return user.code; 
        }, 
        minimumInputLength: 3, 
        multiple: true, 
        ajax: { 
         url: 'api/employee', //This URL points to an internal location and wouldn't work 
         dataType: 'json', 

         data: function (params) { 
          return { 
           q: params.term, // search term 
           page: params.page 
          }; 
         }, 
         results: function(data, page) { 
          return { results: data }; 
         } 
        }, 

        formatResult: function(data) { 
         return "<div class='select2-user-result'>" + data.name + "</div>"; 
        }, 
        formatSelection: function(data) { 
         return data.name; 
        }, 
        initSelection: function(element, callback) { 
         var data = []; 
         $(element.val().split(",")).each(function(i) { 
          var item = this.split(':'); 
          data.push({ 
           id: item[0], 
           title: item[1] 
          }); 
         }); 
         callback(data); 
        } 
       } 
      } 
+0

你已經找到了解決?我面臨同樣的問題。 – 2015-06-24 09:07:20

回答

0

一個匹配需要您選擇2選項加入:

select2Test: { 
    ... 
    matcher: function(term, text, option) { 
     return option.name.includes(term); 
    }, 
    ... 
}