【发布时间】:2018-07-08 15:16:13
【问题描述】:
我正在调用一个 API,它给了我一个 JSON 数组,所以我想将返回的数据分配给 LANDMARKS 变量。
源代码:
export const LANDMARKS : Landmark[] = this.myobj;
console.log(this.myItems);
fetch('https://jsonplaceholder.typicode.com/users')
.then(response => response.json())
.then(json => {this.myItems = json;
console.log(this.myItems);
**const myobj = this.myItems**
// return myobj;
}
);
【问题讨论】:
-
所以您想将
this.myItems分配给Landmark[]? -
Yes this.myItems to Landmark[]
-
如果您从 API 获得响应,请尝试使用:LANDMARKS = this.myItems
-
是的,我很喜欢 .then(json => {this.myItems = json; console.log(this.myItems);在此处输入代码 const myobj = this.myItems 数据在 Landmark[] 中正确显示听到但不显示
-
请格式化代码并删除注释代码
标签: angularjs json nativescript