我正在尝试从wooccomerce api检索一些图像。这是我的代码:
this.config.getWithUrl(this.config.url + '/api/appsettings/get_all_banners/?insecure=cool')
.then((data: any) => {
this.banners = data.data;
console.log(this.banners);
});
我收到此错误:
consolelogs.js:49 ERROR Error: Uncaught (in promise): TypeError: data.data is not iterable
TypeError: data.data is not iterable
at shared-data.service.ts:187
at ZoneDelegate.invoke (zone-evergreen.js:359)
at Object.onInvoke (core.js:34201)
at ZoneDelegate.invoke (zone-evergreen.js:358)
at Zone.run (zone-evergreen.js:124)
.........
这是数据日志:任何对象
{status: "ok", data: Array(2)}
status: "ok"
data: Array(2)
0:
banners_id: "2"
banners_title: "Banner"
banners_url: ""
banners_image: "https://dokanreach.com/wp-content/uploads/2020/02/shop4_home_slider2.jpg"
banners_group: ""
banners_html_text: null
expires_impressions: "0"
expires_date: "2020-02-29 00:00:00"
date_scheduled: null
date_added: "2020-02-21 00:00:00"
date_status_change: null
status: "1"
type: "Select Type"
banners_order: "1"
__proto__: Object
1: {banners_id: "4", banners_title: "Banner2", banners_url: "", banners_image: "https://dokanreach.com/wp-content/uploads/2017/03/01n_bg.jpg", banners_group: "", …}
length: 2
__proto__: Array(0)
__proto__: Object
答案 0 :(得分:0)
您应按照以下方式处理从Api返回的原始结果后,将data.data分配到另一个变量:
this.config.getWithUrl(this.config.url + '/api/appsettings/get_all_banners/?insecure=cool')
.then((data: any) => {
var original_data = JSON.parse(JSON.stringify(data));
console.log(original_data);
this.banners = original_data.data;
console.log(this.banners);
});
我还没有尝试过,但是,有时数据格式不正确,所以可能会引起问题。