【问题标题】:Delete a pushed item in firebase删除firebase中的推送项目
【发布时间】:2018-01-09 15:33:51
【问题描述】:

我想从很久以前推送的firebase中删除一个对象。

  delete: function(){
    var id = $("#locations").val();
    firebase.database().ref('/suppliers/' + this.props.params.id + '/locations/' + id).remove();
  },

在此代码中,Id 表示类似 -L1-b6qyyR52a7RGkw1c 的推送 Id 格式,基于我选择要删除的内容的选择栏。

但该函数失败,没有错误,但没有删除任何内容。

【问题讨论】:

  • 可能是一个 try catch 块,以便我们得到某种错误消息:` delete: function(){ try { var id = $("#locations").val(); firebase.database().ref('/suppliers/' + this.props.params.id + '/locations/' + id).remove(); } 捕捉(错误){ console.log(错误)}}`
  • 你能分享你的firebase数据库截图吗......!

标签: javascript reactjs firebase firebase-realtime-database


【解决方案1】:

考虑到suppliers 是根节点。使用suppliers/ 而不是/suppliers/

试试这个功能

      delete: function(){
        var id = $("#locations").val();
        var ref = firebase.database().firebase.database().ref('suppliers/' + this.props.params.id + '/locations/' + id);
        ref.once("value")
       .then(function(snapshot) {
         snapshot.ref.remove();
       });
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 2017-12-02
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多