【问题标题】:How do I update specific field in Firebase with Push IDs?如何使用推送 ID 更新 Firebase 中的特定字段?
【发布时间】:2018-12-29 05:15:35
【问题描述】:

一旦用户选择其中一个选项,我就会尝试将 状态 更新为“完成”。由于自动生成的推送 ID,我不确定如何读取特定字段。附上firebase数据库截图

Firebase screenshot

【问题讨论】:

  • 查询包含在 Firebase Getting Started Guide 中。此外,请不要在您的问题中包含图片或链接。包括代码和结构作为文本。要获取您的 Firebase 结构,请使用 Firebase 控制台->导出 JSON 并复制粘贴您的结构的 sn-p。见images and links are evil

标签: javascript reactjs firebase firebase-realtime-database


【解决方案1】:

如果您不知道 .push 的节点的 uid,请向 ref 询问 .key,如下所示。要更新,你.update

// Generate a reference to a new location and add some data using push()
var newPostRef = postsRef.push({
  author: "gracehop",
  title: "Announcing COBOL, a New Programming Language"
});
// Get the unique ID generated by push() by accessing its key
var postID = newPostRef.key;

【讨论】:

    猜你喜欢
    • 2017-11-30
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 2019-03-12
    • 2018-07-07
    相关资源
    最近更新 更多