【问题标题】:AngularFire push functionAngularFire推送功能
【发布时间】:2017-07-06 22:18:19
【问题描述】:

我正在使用 angularfire 如下:

 this.afDB.list('/items/' + this.itemID).push({displayName: item.name}); 

结构如下所示,其中itemIDqoieke

items:
    - qoieke:
            - Leow9dnfwoierjhwelo
                                - displayName: "Something"

我不明白的是如何避免将"Leow9dnfwoierjhwelo" 作为自动生成的 id?

所以,我想有如下结构:

items:
    - qoieke:
           - displayName: "Something"

谢谢!

【问题讨论】:

    标签: javascript firebase angularfire2


    【解决方案1】:

    调用push 会生成一个所谓的推送ID。要不生成它,请不要调用 push。而是调用set()(用您传入的任何内容替换该位置的当前值)或update()(仅修改您传入的属性)。

    在您的情况下,update() 似乎可以满足您的要求:

    this.afDB.list('/items/' + this.itemID).update({displayName: item.name}); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 1970-01-01
      • 1970-01-01
      • 2018-06-16
      • 1970-01-01
      相关资源
      最近更新 更多