根据值删除数据表Firebase表

时间:2018-01-22 06:19:35

标签: firebase firebase-realtime-database

我想删除值为“Screen2”的数据

{
 "mobilereg" : {
    "1245639856" : {
      "screen" : "Screen2"
    },
    "1254789632" : {
      "screen" : "Screen2"
    },
    "1452369852" : {
      "screen" : "Screen2"
    },
    "2589632587" : {
      "screen" : "Screen2"
    }
  }
}

删除屏幕值为“Screen2”的数字:

Delte those numbers whose Screen value is "Screen2"

1 个答案:

答案 0 :(得分:0)

要删除firebase中的值,您可以在firebase引用remove()节点上使用mobilereg函数,其中子值为Screen2

let mobileregRef = firebase.database().ref().child("mobilereg")
mobileregRef
  .once('value', s => {
    if (s.exists()) {
      // map through objects returned from mobileregRef and map through the objects
      Object.keys(s.val()).map(k => {
          // deleting the node which contains `Screen2` as value
          if(s.val()[k]=="Screen2"){
            s.ref.remove()
          }
      })
    }
})