简体   繁体   English

React Native Firestore - 获取字段值

[英]React Native Firestore - Get field values

I want to save my field values into a local array.我想将我的字段值保存到本地数组中。
Example:
图片
I will get ["84724302","60855802"] And by the way the field name is not 0 & 1 .我会得到["84724302","60855802"]顺便说一下,字段名称不是0 & 1

When I'm trying to do it with documentSnapshot.data() it returns this result: [{"field_name": "84724302", "field_name": "60855802"}]当我尝试使用 documentSnapshot.data() 执行此操作时,它返回以下结果: [{"field_name": "84724302", "field_name": "60855802"}]
But I need to get this result: ["84724302","60855802"]但我需要得到这个结果: ["84724302","60855802"]

just convert the object that you are getting to an array只需将您要获取的 object 转换为数组

firestore.collection('collection').doc('123').onSnapshot(doc=>{
  const arr=Object.values(doc.data())
 console.log(arr) // ["84724302","60855802"]
//...
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM