AngularJS如何访问嵌套的数据Json?
AngularJS how acces data nested Json?
我正在尝试在 wordpress 中获取 post 的 "thumbnail" 图片。
但我无法访问嵌套的 JSON 数据
我创建了一个 jsFiddle link 这样你就可以看到一个示例并可能完成我的 html 和 AngularJS 控制器。
我可能需要创建一个过滤器。但我不能,我被卡住了。
目标是嵌套该缩略图并将其作为图像放置 src
。
{
"ID": 45,
"title": "Lista Generada",
"status": "publish",
"type": "post",
"modified_gmt": "2015-03-11T21:04:47+00:00",
"featured_image":
{
"ID": 46,
"title": "eCommerce-checklist",
"status": "inherit",
"type": "attachment",
"is_image": true,
"attachment_meta":
{
"width": 1000,
"height": 857,
"file": "2015/03/eCommerce-checklist.jpg",
"sizes":
{
"medium":
{
"file": "eCommerce-checklist-300x257.jpg",
"width": 300,
"height": 257,
"mime-type": "image/jpeg",
"url": "http://localhost/wp-content/uploads/2015/03/eCommerce-checklist-300x257.jpg"
},
"post-thumbnail":
{
"file": "eCommerce-checklist-825x510.jpg",
"width": 825,
"height": 510,
"mime-type": "image/jpeg",
"url": "http://localhost/wp-content/uploads/2015/03/eCommerce-checklist-825x510.jpg"
}
},
}
},
}
使用 ng-src
,而不是 src
。另外,您的 JSON 无效。
首先 "post-thumbnail" 无效,您应该将 - 更改为 _
然后您可以访问您的post_thumbnail。
post.featured_image.attachment_meta.sizes.post_thumbnail.url
我正在尝试在 wordpress 中获取 post 的 "thumbnail" 图片。 但我无法访问嵌套的 JSON 数据 我创建了一个 jsFiddle link 这样你就可以看到一个示例并可能完成我的 html 和 AngularJS 控制器。
我可能需要创建一个过滤器。但我不能,我被卡住了。
目标是嵌套该缩略图并将其作为图像放置 src
。
{
"ID": 45,
"title": "Lista Generada",
"status": "publish",
"type": "post",
"modified_gmt": "2015-03-11T21:04:47+00:00",
"featured_image":
{
"ID": 46,
"title": "eCommerce-checklist",
"status": "inherit",
"type": "attachment",
"is_image": true,
"attachment_meta":
{
"width": 1000,
"height": 857,
"file": "2015/03/eCommerce-checklist.jpg",
"sizes":
{
"medium":
{
"file": "eCommerce-checklist-300x257.jpg",
"width": 300,
"height": 257,
"mime-type": "image/jpeg",
"url": "http://localhost/wp-content/uploads/2015/03/eCommerce-checklist-300x257.jpg"
},
"post-thumbnail":
{
"file": "eCommerce-checklist-825x510.jpg",
"width": 825,
"height": 510,
"mime-type": "image/jpeg",
"url": "http://localhost/wp-content/uploads/2015/03/eCommerce-checklist-825x510.jpg"
}
},
}
},
}
使用 ng-src
,而不是 src
。另外,您的 JSON 无效。
首先 "post-thumbnail" 无效,您应该将 - 更改为 _
然后您可以访问您的post_thumbnail。
post.featured_image.attachment_meta.sizes.post_thumbnail.url