数组对象属性键名更改的方法及uni-data-picker组件的属性转换

uniapp 的级联选择器组件:uni-data-picker

问题是该组件只接受text和value两个键名的数据级联选择

所以需要将后台传来的数据进行修改,将键名改为text和value即可

 1const newData = res.items.map((item) => {
 2      return {
          //通过map遍历修改键名
3  text: item['pay_name'], 4 value: item['pay_id'],
          //修改子元素键名,此处注意map无法处理null,在子元素为null要传个空数组
5 children: (item.children || []).map((item2) => { 6 return { 7 text: item2['pay_name'], 8 value: item2['pay_id'] 9 } 10 }) 11 } 12 }) 13 this.array = newData 14 console.log(newData)

 

posted @ 2023-03-08 11:26  野望之风  阅读(251)  评论(0编辑  收藏  举报