0

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

所以我有以下标记

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

返回的静止角数据

[
{"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;
    }
}
4

1 回答 1

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;

    });

希望这会有所帮助..

于 2014-07-22T13:00:51.830 回答