如何在AngularJS中使用ng-repeat迭代多个地图(键,值)

时间:2022-09-18 14:31:19

In my controller, I have data like this:

在我的控制器中,我有这样的数据:

"type":       [
              {
        "aMap": {"5.0": 0},
        "bMap": {"10.0": 0},
        "cMap": {"15.0": 0},
        "dMap": {"20.0": 0},
        "desc": "CG"
},
{
        "aMap": {"5.0": 0},
        "bMap": {"10.0": 0},
        "cMap": {"15.0": 0},
        "dMap": {"20.0": 0},
        "desc": "CG"
}]

It contains arrays which has multiple maps. I want to read both key, value in the maps in my html using ng-repeat. How can I do this?

它包含具有多个映射的数组。我想使用ng-repeat在html中的地图中读取关键值。我怎样才能做到这一点?

2 个解决方案

#1


0  

In your view you can loop using:

在您的视图中,您可以循环使用:

<div ng-repeat="item in type">
    <div ng-repeat="(key, val) in item">
      <b>KEY</b> : {{key}}
      <b>ITEM</b> : {{val}}
      <br/>
      <i>KEY / VAL of data :</i>
      <div ng-repeat="(keylower, vallower) in val">
        {{keylower}} - {{vallower}}
      </div>
      <br/><br/>
    </div>
</div>

See this code example on Plunkr : https://plnkr.co/edit/nXEwJ5IcD4Cu8wrFjR2R?p=preview

请参阅Plunkr上的以下代码示例:https://plnkr.co/edit/nXEwJ5IcD4Cu8wrFjR2R?p = preview

#2


0  

You can use ng-repeat like this:

您可以像这样使用ng-repeat:

<div ng-repeat="foo in data">
  <div ng-repeat="(key, val) in foo">

#1


0  

In your view you can loop using:

在您的视图中,您可以循环使用:

<div ng-repeat="item in type">
    <div ng-repeat="(key, val) in item">
      <b>KEY</b> : {{key}}
      <b>ITEM</b> : {{val}}
      <br/>
      <i>KEY / VAL of data :</i>
      <div ng-repeat="(keylower, vallower) in val">
        {{keylower}} - {{vallower}}
      </div>
      <br/><br/>
    </div>
</div>

See this code example on Plunkr : https://plnkr.co/edit/nXEwJ5IcD4Cu8wrFjR2R?p=preview

请参阅Plunkr上的以下代码示例:https://plnkr.co/edit/nXEwJ5IcD4Cu8wrFjR2R?p = preview

#2


0  

You can use ng-repeat like this:

您可以像这样使用ng-repeat:

<div ng-repeat="foo in data">
  <div ng-repeat="(key, val) in foo">