2014-07-22 50 views
0

選擇2標籤我怎麼會通過標籤如果對象使用restangular與restangular響應

所以我下面的標記

<input type="hidden" ui-select2="select2Options" style="width:100%" ng-model="list_of_string"> 

返回restangular數據

[ 
{"count":"13","brand":"2DIRECT GMBH"}, 
{"count":"12","brand":"3M DEUTSCHLAND GMBH"}, 
{"count":"1","brand":"a-rival"} 
] 
來源於問題的REST API選擇2

這裏是我的控制器方法

var filterProducts = function($scope, api) { 
    api.categories().then(function(response) { 
     //this is the respose what I would like to use in select2 tags 
     $scope.brands = response; 
    }); 

    $scope.list_of_string = ['tag1', 'tag2'] 
    $scope.select2Options = { 
     'multiple': true, 
     'simple_tags': true, 
     'tags': ['tag1', 'tag2', 'tag3', 'tag4'] // Can be empty list. 
    }; 

}; 

更新

最後我管理

和孔看起來像

$scope.select2Options = { 
    data: function() { 
     api.categories().then(function(response) { 
      $scope.data = response; 
     }); 

     return {'results': $scope.data}; 
    }, 
    'multiple': true, 
    formatResult: function(data) { 

     return data.text; 
    }, 
    formatSelection: function(data) { 
     return data.text; 
    } 
} 

回答

0
var filterProducts = function($scope, api) { 
    api.categories().then(function(response) { 
     //this is the respose what I would like to use in select2 tags 
     $scope.brands = response; 
     $scope.select2Options.tags = response; 

    }); 

希望這將有助於..

+0

您好我想不工作 – fefe

+0

結帳這個http://stackoverflow.com/questions/15680336/angular-ui-select2-tagging-update-the-data-value – dhavalcengg