如何将通过条件查询得到的res中以某一字段为关键字遍历出来的数据赋值给新的数组?

小程序 文章 2021-02-04 11:01 431 0 全屏看文

AI助手支持GPT4.0

如何将通过条件查询得到的res中以某一字段为关键字遍历出来的数据赋值给新的数组?How to assign the data traversed by a certain field as the key in res obtained by conditional query to a new array?

如何将通过条件查询得到的res中以某一字段为关键字遍历出来的数据赋值给新的数组?

云数据库查询,得到一个res数组

将数组的数据,长度在调试界面打印出来

打印结果:51行是res;52行是res.data;53行是res.data.length

我想实现的是将res.data中以seathao字段为关键字遍历出来的数据赋值给新的数组,以作为下一个picker的数据

但是每次一遍历或者this.setdata赋值都是不成功的

求大佬们指点!!!

Query the cloud database to get a res array, and print the data and length of the array in the debugging interface. The print result is: 51 lines are res; 52 lines are res res.data ; 53 yes res.data.length What I want to achieve is to res.data The data traversed by using the seathao field as the keyword is assigned to the new array as the data of the next picker, but every time or this.setdata Assignment is not successful, ask big guys to point out!!!

回答:

จุ๊บXavier:

picker | 微信开放文档

你如果只想给个数组给 picker ,可以这样处理数据

[{  a: 1,  b: 2}, {  a: 3,  b: 4}].map(item => {  return item.a})// [1, 3]
冢.:

用concat无显示,用push显示两个并排的object

จุ๊บXavier:
|G.XIAO|:

Object.keys 能拿到对象的keys 数组

冢.:老师这个Object.keys一下子就将所有的其他关键字也遍历出来了,怎么指定关键字遍历鸭?我是想将res。data数组里的seathao都遍历出来出来,放到array2中,请老师指点一下

-EOF-

AI助手支持GPT4.0