【问题标题】:Firebase - update() value in databaseFirebase - 数据库中的更新()值
【发布时间】:2018-03-12 00:55:34
【问题描述】:

我正在尝试 update() 我的 firebase 数据库中的一个值,但我很挣扎。

我第一次这样做:

  this.database.list('/replies/'+this.postData.parent+'/'+this.postData.id).update('score', this.voteCount)

认为这会起作用,但我得到了一个错误:

错误错误:Reference.update 失败:第一个参数必须是包含要替换的子对象的对象。

然后我尝试了:

this.database.list('/replies/'+this.postData.parent+'/'+this.postData.id).update({'score': this.voteCount})

this.voteCount 是一个整数。

我收到以下错误:

ERROR 错误:需要字符串、快照或引用。得到:对象

我真的很困惑为什么它首先要一个对象,然后告诉我它不想要一个对象..

如果我将update() 更改为set() 并保持为('score', this.voteCount),它可以正常工作,但我不想设置它,如果它存在我想更新它..

我做错了吗?谢谢!

【问题讨论】:

    标签: javascript angular firebase firebase-realtime-database


    【解决方案1】:

    尝试:

    this.database.ref('/replies/'+this.postData.parent+'/'+this.postData.id).update({'score': this.voteCount})
    

    【讨论】:

    • 是的,谢谢你的工作。对我来说,我必须做this.database.database.ref。欣赏!
    猜你喜欢
    • 2017-09-04
    • 2019-07-03
    • 1970-01-01
    • 1970-01-01
    • 2018-02-11
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    相关资源
    最近更新 更多