使用AngularJS显示json数据

时间:2015-12-29 04:55:26

标签: javascript angularjs json

当我的程序获得这样的JSON响应时:

[
    {
      "index": 1,
      "name": "Samantha",
      "rarity": "Scarborough",
      "email": "maureen@sykes.mk"
    },
    {
      "index": 2,
      "name": "Amanda",
      "rarity": "Vick",
      "email": "jessica@livingston.mv"
    }
]

AngularJS显示ng-repeat欺骗错误。我也尝试过使用:$index跟踪。

但如果我的JSON响应是这样的:

{"items": 
   [
    {
      "index": 1,
      "name": "Samantha",
      "rarity": "Scarborough",
      "email": "maureen@sykes.mk"
    },
    {
      "index": 2,
      "name": "Amanda",
      "rarity": "Vick",
      "email": "jessica@livingston.mv"
    }
  ]
}

我可以使用ng-repeat = "name in variable.items"

轻松显示JSON

为什么AngularJS的行为如此?

0 个答案:

没有答案