如何解析angularjs中的多数组json数据

时间:2018-04-29 08:46:22

标签: javascript arrays angularjs json

我通过Angularjs中的API调用获得了多数组json响应。但是在通过ng-repeat迭代值时,数组值会分成每个字符。我不明白如何解析它。

例如它应该迭代'颜色 - 绿色',但我得到它'c','o','l','o','r','g','r','e','e','n' ...你能帮助我得到它。以下是plnkr链接

http://plnkr.co/edit/gppDyJ4FJ9x78aDkiwMW?p=preview

我迭代的代码部分是:

$http({method: 'GET', url: 'colors.json'}).success(function(data) {
    $scope.artists = [];
    angular.forEach(data.colors, function(value, key) {         
        $scope.colorList = value;       
    });     
});

colors.json文件包含:

{
    "colors": {
         "blue":["color-blue","color-blue-08","color-blue-06","color-blue-04","color-blue-02"],
         "red":["color-red","color-red-08","color-red-06","color-red-04","color-red-02"],
         "skyblue":["color-skyblue","color-skyblue-08","color-skyblue-06","color-skyblue-04","color-skyblue-02"],
         "orange":["color-orange","color-orange-08","color-orange-06","color-orange-04","color-orange-02"],
         "grey":["color-grey","color-grey-08","color-grey-06","color-grey-04","color-grey-02"],
         "green":["color-green","color-green-08","color-green-06","color-green-04","color-green-02"]
    }
}

2 个答案:

答案 0 :(得分:0)

您需要将对象推送到数组而不是分配它们

ls | cat -n | while read n f; do mv "$f" "10_$n.png"; done

CORRECTED DEMO

答案 1 :(得分:-1)

There was a little mistake in the way your were getting the values into the 
scope

I've forked your pluker.

Plunker