最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can't select item in list created by ui-select2 - Stack Overflow

programmeradmin2浏览0评论

In my HTML I have this line:

<input  ng-change="privChanged()" ng-model="selectedPriv" ui-select2="privsSelect2options"></input>

and the privsSelect2options function:

$scope.privsSelect2options = {
    placeholder: "Wybierz privo",
    allowClear:true,
    minimumInputLength: function(){return  3;},
    formatInputTooShort: function (input, min) {return "Wprowadź conajmniej " + min + " znaki.";},
    formatSearching: function () { return "Wyszukiwanie..."; },
    formatNoMatches: function () { return "Nie znaleziono pasujących województw."; },
    query: function (query) {
       query.callback( {results: $filter('filter')($scope.privs,{name: query.term}) } );
    },
    formatResult: function(priv){
        return priv.name;
    },
    formatSelection: function(priv){
        return priv.name;
    }
}; 

Everything works OK when I put 3 letters it filters the result and shows it correct but I can't click and select any item from the result list. Can anyone help me in this matter? It doesn't even come into the formatSelection function.

In my HTML I have this line:

<input  ng-change="privChanged()" ng-model="selectedPriv" ui-select2="privsSelect2options"></input>

and the privsSelect2options function:

$scope.privsSelect2options = {
    placeholder: "Wybierz privo",
    allowClear:true,
    minimumInputLength: function(){return  3;},
    formatInputTooShort: function (input, min) {return "Wprowadź conajmniej " + min + " znaki.";},
    formatSearching: function () { return "Wyszukiwanie..."; },
    formatNoMatches: function () { return "Nie znaleziono pasujących województw."; },
    query: function (query) {
       query.callback( {results: $filter('filter')($scope.privs,{name: query.term}) } );
    },
    formatResult: function(priv){
        return priv.name;
    },
    formatSelection: function(priv){
        return priv.name;
    }
}; 

Everything works OK when I put 3 letters it filters the result and shows it correct but I can't click and select any item from the result list. Can anyone help me in this matter? It doesn't even come into the formatSelection function.

Share Improve this question edited Mar 28, 2013 at 21:35 j0k 22.8k28 gold badges81 silver badges90 bronze badges asked Mar 26, 2013 at 14:09 biesczadkabiesczadka 5811 gold badge7 silver badges20 bronze badges 2
  • 1 Can you attach privChanged() function definition to the question. – Stewie Commented Mar 26, 2013 at 15:10
  • yes, I attached it. the problem was sth else. I post in answer – biesczadka Commented Mar 29, 2013 at 12:03
Add a comment  | 

3 Answers 3

Reset to default 20

the problem was that Priv class/table didn't have id property, and its Primary Key was field code. I had to add function :

id : function(priv) {
        return priv.code;
     },

in $scope.privNameSelect2options

Please refer to Select2 Ajax Method Not Selecting,

and take the correct value:

id: function(data){return {id: data.id};},

or

id: function(data){return data.id}

Although this isn't really specified in the select2 documentation, you'll need to pass an id key with a function value to select2.

$scope.privsSelect2options = {
    id: function(element) { return element.name; }
    ...
}; 
发布评论

评论列表(0)

  1. 暂无评论