选择2个具有restangular响应的标签



如果对象来自使用restangular的restfull API,我如何将标记传递给select2

所以我有以下标记

<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"}
]

这是我的控制器方法

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;
    }
}
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;
    });

希望这会有所帮助。。

相关内容

  • 没有找到相关文章

最新更新