AngularFire 推送功能

AngularFire push function

我正在使用如下的angularfire:

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

结构看起来像这样 itemIDqoieke

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

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

所以,我想要如下结构:

items:
    - qoieke:
           - displayName: "Something"

谢谢!

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

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

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