使用Ng Repeat访问匿名数组

时间:2015-03-24 18:32:18

标签: javascript arrays angularjs object angularjs-ng-repeat

我有一个包含最深层对象的多级数组。

[  
   [  
      [  
         "FUND",
         {  
            "totassets":10.9,
            "totdate":"2015-03-23",
            "expratiogross":1.35,
            "exprationet":1.08
         }
      ],
      [  
         "DAILY",
         {  
            "navdate":"2015-03-23",
            "nav":10.05,
            "chgamt":0,
            "chgpct":0,
            "pop":10.05,
            "ytdreturn":2.03,
            "curr7dayyield":0,
            "eff7dayyield":0,
            "unsub7dayyield":0,
            "30dayyield":0,
            "30dayloadyield":0
         }
      ]
   ]
]

我想使用ngRepeat显示" FUND"中的所有项目。或"每日"但我不确定如何深入访问这些对象而没有上面每个数组的名称。

很抱歉,如果这是一个基本问题,但我无法在其他地方找到答案。

2 个答案:

答案 0 :(得分:1)

您想要获得两个外部数组的第一个元素。

$scope.obj = [  
   [  
      [  
         "FUND",
         {  
            "totassets":10.9,
            "totdate":"2015-03-23",
            "expratiogross":1.35,
            "exprationet":1.08
         }
      ],
      [  
         "DAILY",
         {  
            "navdate":"2015-03-23",
            "nav":10.05,
            "chgamt":0,
            "chgpct":0,
            "pop":10.05,
            "ytdreturn":2.03,
            "curr7dayyield":0,
            "eff7dayyield":0,
            "unsub7dayyield":0,
            "30dayyield":0,
            "30dayloadyield":0
         }
      ]
   ]
]

<ng-repeat el in obj[0][0]>
  <span>totassets: {{el[0].FUND.totalAssets}}</span>
  <span>navdate: {{el[0].DAILY.navdate}}</span>
</ng-repeat>

答案 1 :(得分:0)

你对数组的一个问题是,即使你忽略外部数组,你仍然会留下两个单独的数组a la:

  [  
     "FUND",
     {  
        "totassets":10.9,
        "totdate":"2015-03-23",
        "expratiogross":1.35,
        "exprationet":1.08
     }
  ],

  [  
     "DAILY",
     {  
        "navdate":"2015-03-23",
        "nav":10.05,
        "chgamt":0,
        "chgpct":0,
        "pop":10.05,
        "ytdreturn":2.03,
        "curr7dayyield":0,
        "eff7dayyield":0,
        "unsub7dayyield":0,
        "30dayyield":0,
        "30dayloadyield":0
     }
  ]

因此,您需要两个ngRepeat块来实现我想要实现的目标,并且更深层次以实际访问您想要的值。

这是一个快速的plnkr来展示我的意思:http://plnkr.co/edit/ArCh8q8w2JoXsg107XwP?p=preview