如何从Firebase数据库Java脚本中的数据数组中获取特定对象

时间:2019-02-13 08:46:40

标签: javascript node.js firebase react-native firebase-realtime-database

在我的Firebase实时数据库中,我有表bookings,其中包含类似数据,

 "booking_id1": [
   {
      "id":"1","name":"ram"
    },{
       "id":"2","name":"raj"
    },{
       "id":"3","name":"ramraj"
    }
  ],
"booking_id2": [
   {
      "id":"4","name":"ram"
    },{
       "id":"5","name":"raj"
    },{
       "id":"6","name":"ramraj"
    }
  ]

现在我是否喜欢使用

Firebase.database().ref('/bookings').once("value", snapshot => {
});

它会得出所有数据,例如

 {
    "booking_id1": [
   {
      "id":"1","name":"ram"
    },{
       "id":"2","name":"raj"
    },{
       "id":"3","name":"ramraj"
    }
  ],
"booking_id2": [
   {
      "id":"4","name":"ram"
    },{
       "id":"5","name":"raj"
    },{
       "id":"6","name":"ramraj"
    }
  ]
 }

但是我只想使用id=4获得对象。喜欢,

{
"booking_id2": [
   {
      "id":"4","name":"ram"
    },{
       "id":"5","name":"raj"
    },{
       "id":"6","name":"ramraj"
    }
  ]
}

任何建议都会有所帮助...谢谢

0 个答案:

没有答案