我将 AngularJS 与 WordPress Rest API 一起使用。我正在发出一个返回对象的获取请求。要获得特色图像,我必须使用“?embed”参数,它给出了另一个名为 _embedded 的对象。
问题是我想要的 _embedded 内的对象称为 wp:featuredmedia。如果我像这样以角度引用它,则会出现语法错误。
这是我的代码
$http.get(queries[0], {'cache': true}).
then(function(response) {
$scope.careers_title = strip(response.data.title.rendered);
$scope.careers_content = strip(response.data.content.rendered);
$scope.careers_feature_image = strip(response.data.featured_media);
console.log(response.data._embedded);
});
console.log 返回这个
Object {author: Array[1], wp:featuredmedia: Array[1], wp:term: Array[2]}author: Array[1]wp:featuredmedia: Array[1]0: Object_links: Objectalt_text: ""author: 1date: "2016-04-25T09:33:52"id: 46link: "http://localhost:8888/rubis/wordpress/energy-efficiency/tp-roundall/"media_details: Objectmedia_type: "image"mime_type: "image/png"slug: "tp-roundall"source_url: "http://localhost:8888/rubis/wordpress/wp-content/uploads/2016/04/tp-roundall.png"title: Objecttype: "attachment"__proto__: Objectlength: 1__proto__: Array[0]wp:term: Array[2]__proto__: Object