基本上你已经拥有了一切。你需要做的就是在地图上设置每个if和itacate的返回值,地图上的每一个项目都是集合的对象。
function fetchRequests (){
....
}).then(responde => response.json())
.then(responde => {
const { result, collection } = response;
If (result===“success”) {
return collection.map(item => new Person(item))
}
})
你需要在集合上为你得到的对象创建一个新的类。
class Perdon {
constructor (data) {
Object.assign(this, data);
}
}
在你调用方法fetchRequests的任何地方。
async function funcCaller () {
const people = await fetchRequests();
// people have your collection
}