【问题标题】:Populate vertical table from two different arrays using ng-repeat使用 ng-repeat 从两个不同的数组填充垂直表
【发布时间】:2018-04-12 22:01:59
【问题描述】:

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

在这, Vertical ng-repeat 问题,使用相同的数组填充所有列,但是我想用不同的数组填充每一列 这是我的 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"
        }
    ]
}

}

提前致谢

【问题讨论】:

    标签: html angularjs arrays json


    【解决方案1】:

    解决后,我想出的解决方案是在 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>
    

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

    【讨论】:

      猜你喜欢
      • 2018-12-16
      • 1970-01-01
      • 1970-01-01
      • 2015-03-19
      • 1970-01-01
      • 2016-03-22
      • 1970-01-01
      • 2014-06-18
      • 2023-03-25
      相关资源
      最近更新 更多