使用ng-repeat从两个不同的数组填充垂直表

时间:2017-10-31 16:43:26

标签: html angularjs arrays json

我正在尝试从JSON数据构建一个垂直表。但是我的问题是我有3列,第一列是该列的名称。其余两列必须由2个不同的数组填充。

在此, Vertical ng-repeat问题,使用相同的数组正在填充所有列,但是我想用不同的数组填充每个列 Here the one column data is about one college and is coming from 1st array,second column should be filled by second array. 这是我的JSON

{
"result": {
    "college1": [
        {
            "lyr": "0",
            "rating": "",
            "code": "",
            "nirf": "0",
            "mhrd": "0",
            "outlook": "0",
            "tiem": "0",
            "career": "0",
            "naac": "0",
            "fees": "50000",
            "pla": "0",
            "image": "king.jpg"
        }
    ],
    "college2": [
        {
            "lyr": "0",
            "rating": "",
            "code": "",
            "nirf": "0",
            "mhrd": "0",
            "outlook": "0",
            "tiem": "0",
            "career": "0",
            "naac": "0",
            "fees": "25000",
            "pla": "0",
            "image": "king.jpg"
        }
    ]
}

}

提前致谢

1 个答案:

答案 0 :(得分:0)

在解决之后,我想出的解决方案是在ng-repeat中迭代我的json数组的键值对。我使用$ index来遍历第二个数组。 这是我的代码:`

                <tr ng-repeat="(key, value) in college1[0]">

                    <td class="col-md-6 head-field active">{{key}}</td>
                    <td class="col-md-3" ng-repeat="x in data1">
                        {{x[key]}}
                    </td>
                    <td class="col-md-3" ng-repeat="x in data1">
                        {{college2[$index][key]}}
                    </td>
                </tr>

` 刚刚发布了解决方案,以便它可以帮助将来遇到类似问题的人: - )

相关问题