【问题标题】:How to push data in array stored in the Firebase using angularfire2?如何使用 angularfire2 推送存储在 Firebase 中的数组中的数据?
【发布时间】:2017-10-19 05:30:50
【问题描述】:

我正在使用 angularfire2 将数据存储在 firebase 数据库中。我需要将数据添加到存储在数据库中的数组中,如下所示:

places: 0:"new Item" 1:"new Item", 2:"new Item" . . .

等等,这就是我需要的。 但就我而言,数据如下所示:

这是我的代码:

this.user = this.db.list("/Users/"+ this.currentUserId+'/places'); this.user.push(["new Item"]);

当用户输入新位置时,我需要将新数据输入到数组中,而不是插入新数组。

谢谢。

【问题讨论】:

    标签: arrays database angular firebase angularfire2


    【解决方案1】:

    您正在推送一个数组,请尝试推送一个对象。示例:

    this.user.push({description: "new Item"});
    

    【讨论】:

    • 嗨,它看起来像`地点:asdjasdjdjasas description:"new Item"`
    • 我需要由 firebase 0 1 2 生成的密钥
    • 正好在地点标题下
    • Firebase 没有对数组的原生支持。如果你存储一个数组,它实际上会被存储为一个以整数作为键名的“对象” - firebase.googleblog.com/2014/04/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    • 2020-02-01
    • 2019-12-16
    相关资源
    最近更新 更多