在data里声明了upMenuList数组和message数据,怎么把数组项赋值给空数组啊?

小程序 文章 2022-03-14 16:00 321 0 全屏看文

AI助手支持GPT4.0

在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

回答:

八九:

要么写死,要么this.setData

秋月白:大神,具体什么setData啊,教教我吧谢谢
八九:建议恶补下js
小黎:

let arr=this.data.message.map((res)=>{return res.honor_name})

this.setData({ upMenuList:arr })

秋月白:还是一个空数组啊,不行啊
小黎: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 })
秋月白:大神,不行啊,下面显示还是空的,怎么整?
.:你的getCates方法在onLoad里面调用了没有?
或者你直接卸载onLoad里面试试

-EOF-

AI助手支持GPT4.0