获取阵列的Firebase实时数据库

时间:2019-05-22 17:33:30

标签: firebase react-native firebase-realtime-database redux react-redux

我想获取多个指定的孩子。可以一次提取吗?

我尝试使用orderByChild和equalTo

我的数据结构:

"lections" : [ {
    "id" : 1,
    "title" : "Hello"
  }, {
    "id" : 2,
    "title" : "World"
  }, {
    "id " : 3,
    "title" : "foo"
  }, {
    "id" : 4,
    "title " : "bar"
  } ],
const lections = [1,3,4];


return (dispatch) => {
    firebase
      .database()
      .ref(`lections/${lections}`) 
      //.orderByChild('id')
      //.equalTo(lections)
      .on('value', snapshot => {
        dispatch({ type: LECTIONS_FETCH_SUCCESS,     payload:snapshot.val()});
      });
  };

我希望能回来:

{
"0":{"id":"1","title":"hello"},
"1":{"id":"3","title":"foo"},
"2":{"id":"4","title":"bar"}
} 

谢谢您的帮助:)

0 个答案:

没有答案