如何在AngularJS中拆分二维JSON数组

时间:2015-08-14 04:54:08

标签: angularjs

我有一个像这样的JSON数组:

[["abcd@gmail.com","joe"], ["xyz@gmail.com","brain"], ["hhh@gmail.com","bob"]]

如何单独获取值?

<div class="item item-divider item-input-wrapper">
    {{ email should be here }} : {{ name here }}
</div>          

我需要单独发送电子邮件和名称,但它没有显示任何内容。

2 个答案:

答案 0 :(得分:2)

这是一个小提琴:http://jsfiddle.net/sinaidoron/1c12r4hr/2/ 这是一种可行的方法

var myApp = angular.module('myApp',[]);


function MyCtrl($scope) {
    var persons = [["abcd@gmail.com","joe"],["xyz@gmail.com","brain"],["hhh@gmail.com","bob"]];

    var newPersons = [];
    for(var i=0; i< persons.length; i++){
        var tempObj = {};
        tempObj.email = persons[i][0];
         tempObj.name = persons[i][1];
        newPersons.push(tempObj);
    }
console.log(newPersons)
    $scope.persons = newPersons;

}

<div ng-controller="MyCtrl">
    <div ng-repeat="person in persons">
        {{person.email}} {{person.name}}
    </div>
</div>

答案 1 :(得分:1)

<强>控制器:

$scope.data = [["abcd@gmail.com","joe"],["xyz@gmail.com","brain"],["hhh@gmail.com","bob"]];

<强> HTML

<div class="item item-divider item-input-wrapper" ng-repeat="each in data">
  {{ each[0] }} : {{ each[1] }}
</div>