如何在 firebase 列表的最后写一个数组?

How to write an array in the last of the list in firebase?

我想将我的数据写入列表,但不想覆盖。我希望能够写入相同的数据,但写入 firebase 中同一数组的不同位置。

喜欢:

历史
----- 0 ----用户:test1
------1 ----用户:test2
------2 ---- 用户:test1

但是在我的代码中,我只能写入 0,而不能创建新数据。好像数据被覆盖了。

Java 脚本:

this.test = [{[user]: { data.... }];

public af: AngularFireDatabase

 this.af.object("/history").set(this.teste);

关键在于你的前几句话:

I want to write my data to the list

既然你提到了 list,你应该使用 AngularFire list() API - 而不是你现在正在做的 object() API。根据文档,将项目添加到列表的工作方式如下:

this.af.list("/history").push(this.teste);

请注意,您将获得 Firebase 推送 ID,而不是问题中的 012,因为 Firebase 不使用此处解释的顺序增量索引 Best Practices: Arrays in Firebase.