想要把message里的honor_name赋值给upMenuList怎么实现啊,大佬们帮帮忙
在data里声明了upMenuList数组和message数据,怎么把数组项赋值给空数组啊?The upMenuList array and message data are declared in the data. How to assign the array items to the empty array?
在data里声明了upMenuList数组和message数据,怎么把数组项赋值给空数组啊?想要把message里的honor_name赋值给upMenuList怎么实现啊,大佬们帮帮忙
Want to put the honor in message_ How to realize the assignment of name to upmenulist? Big guys help
回答:
let arr=this.data.message.map((res)=>{return res.honor_name})
this.setData({ upMenuList:arr })
1,声明一个空数组
2,循环遍历message这个数组,取出honor_name字段,push到新数组里面去
3,给upMenuList赋值声明的数组
let arr = []this.data.message.forEach(item=>{ arr.push(item.honor_name)})this.setData({ upMenuList:arr })
要么写死,要么this.setData