代码之家  ›  专栏  ›  技术社区  ›  James Delaney

如何使firebase cloud onUpdate函数正常工作?

  •  0
  • James Delaney  · 技术社区  · 6 年前

    那真的很管用。

    在我的Comments组件中,我有完整的逻辑来获取数据并保存在firebase中。

    现在我想在这里添加一个onUpdate-fb-cloud函数。

    我试了下一条路,但没有成功:

    const onCommentsAdded = this.runtime.fb.ref('/comments').onUpdate((change) => {
      const after = change.after;
      console.log('This is after: ', after, change.after)
    })
    

    无法编译应用程序, 这是一个错误

    未处理的拒绝(TypeError):runtime.fb.ref(…).onUpdate不是 功能

    1 回复  |  直到 6 年前
        1
  •  2
  •   sketchthat    6 年前

    假设你在看 Realtime Database

    您尝试访问的库看起来不正确。看到了吗 Database Events 文档。

    const onCommentsAdded = functions.database.ref('/comments')
      .onUpdate((change, _context) => {
        const after = change.after;
        console.log('This is after: ', after, change.after)
       });
    

    functions.database.ref 而不是 this.runtime.fb.ref