[英]Best way to read objects data in realtime databse to convert it to an array
I want to read the data that i have in the realtime firebase, but when i read it, the data comes with objects inside the array, so i cant use *ngFor to access the data like i am use to.我想读取实时 firebase 中的数据,但是当我读取它时,数据带有数组内的对象,所以我不能像以前那样使用 *ngFor 来访问数据。
I have this data in the realtime database:我在实时数据库中有这些数据:
waiting
|
---------olaaaa
| |
| ----------test1
|
---------olaaaaa2
| |
| -----------test2
when i read the data, the array comes like this :当我读取数据时,数组是这样的:
{ olaaaa: {}, olaaaa2: {} }
and i don't want that, i want the array to come without the names olaaa and olaaa2.我不希望那样,我希望数组没有名称 olaaa 和 olaaa2。 Like this:像这样:
{{test},{test2}}
To read i use this:要阅读我使用这个:
this.af.object("/waiting").query.once('value')
How can i get the info like arrays and not objects?我怎样才能得到像数组而不是对象这样的信息?
I am not familiar with firebase, but what I have read you could add a .then()
to your call and format your data using Object.keys(data).map(key => data[key])
which I found from this post我不熟悉 firebase,但我读过的内容您可以在调用中添加.then()
并使用我从中找到的Object.keys(data).map(key => data[key])
格式化数据邮政
let res = [];
this.af.object("/waiting").query.once('value')
.then(data => {
res = Object.keys(data).map(key => data[key]);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.