我有一个名为 ProductImages 的 Angular Controller ,它返回以下 JSON 数据:
{
"Product_1":[
{ "image_id":"12469",
"name":"My Product 1 - Variety 1",
"url":"\/\/mystorefront.net\/120\/small\/1911791794.jpg"
},
{
"image_id":"12470",
"name":"My Product 1 - Variety 2",
"url":"\/\/drfuittf5cya9.cloudfront.net\/121\/small\/1911802897.jpg"
}
],
"Product_2":[
{ "image_id":"122349",
"name":"My Product 2 - Variety 1",
"url":"\/\/drfuittf5cya9.cloudfront.net\/122\/small\/1911791794.jpg"
},
{
"image_id":"123470",
"name":"191123897.jpg",
"name":"My Product 2 - Variety 2",
"url":"\/\/drfuittf5cya9.cloudfront.net\/123\/small\/1911802897.jpg"
}
]
}
在我的 Angular 代码中我写了:
<div ng-controller="productImages">
<div ng-repeat="product in products">
{{product.image_id}}
</div>
</div>
当我运行此命令时,ng-repeat div
会重复两次,但product.image_id 不会显示。如果我改为 {{product}}
或 {{product.image_id}}
我会打印整个 JSON。
如何在 angularJS 中打印此 JSON?另外,如何打印Product_1、Product_2?
最佳答案
您的对象 Product_1
似乎是一个包含图像的数组。
我认为您需要嵌套 for 循环来显示图像
关于javascript - 在 AngularJS 中读取 JSON 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33545797/