首页 > 解决方案 > 如何遍历angularjs中的json对象数组

问题描述

我有一个具有以下 json 结构的自动搜索模块。我需要遍历一系列 json 对象并根据要求使用键和值。

我试过下面的代码。但是使用提供的 json 对象,我可以检索键,但不能检索值。

可以说,对于第一个 Json 对象,我需要检索“Apple 产品”。但我得到的只是链接。

我试过response.data[key][0]了,但是得到了完整的 json 对象。请问我哪里做错了。

我在下面更新了 plunker

[{
    "/folder1/folder2/folder3/product-1": "Product Apple"
  },
  {
    "/folder1/folder2/folder3/product-2": "Product samsung"
  },
  {
    "/folder1/folder2/folder3/product-3": "Product lenovo"
  },
  {
    "/folder1/folder2/folder3/product-4": "Product Asus"
  },
  {
    "/folder1/folder2/folder3/product-5": "Product Acer"
  },
  {
    "/folder1/folder2/folder3/product-6": "Product Vivo"
  },
  {
    "/folder1/folder2/folder3/product-7": "Product Oppo"
  }
]

代码在这里

标签: javascriptarraysangularjsjson

解决方案


Since this is marked as duplicate post., I have gone through the provided solution and found that the duplicate post has solution via javascript. But I`m looking to iterate through angularjs 'ng-repeat'.

Please find plunker below for solution I have got

[code here][1]

code here


推荐阅读