gmv() {
this.get("/prod-api/api/movie/film/list").then(res => {
return res.rows.map(async item => {
return await this.get("/prod-api/api/movie/film/comment/list", {
'movieId': item.id
}).then(res => {
return {
n: item.name,
c: res.total
}
})
})
}).then(resc => {
Promise.all(resc).then(i => {
i.sort((a,b)=>b.c-a.c)
this.chd.cd.categories = i.slice(0,5).map(item=>item.n)
this.chd.cd.series = [{
type:"scatter",
name:"评论数",
data:i.slice(0,5).map(item=>item.c)
}]
})
})
}
reduce 版本。。
gmv() {
this.get("/prod-api/api/movie/film/list").then(res => res.rows.reduce((acc, item) => {
acc.push(this.get("/prod-api/api/movie/film/comment/list", {
'movieId': item.id
}).then(res => ({
n: item.name,
c: res.total
})))
return acc
}, []))
.then(resc => {
Promise.all(resc).then(i => {
i.sort((a, b) => b.c - a.c)
this.chd.cd.categories = i.slice(0, 5).map(item => item.n)
this.chd.cd.series = [{
type: "scatter",
name: "评论数",
data: i.slice(0, 5).map(item => item.c)
}]
})
})
},
大概就这么个逻辑,简单的一批,别再费脑子想了,赶紧度娘csdn😂😂😂😂😂🤣