如何在firebase中进行多个连接查询?

时间:2016-06-26 14:27:02

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

我用firebase@2.4.2使用react native。我发现很难执行多个连接查询。有人可以指导我,还是有多个加入的图书馆?

以下是我的数据结构,我想加入他们。

chats: {
 chatID1: {
  lastMessage: "Hi",
  userID: "userID1"
 },
 chatID2: {
  lastMessage: "Hahahahahhaa",
  userID: "userID2"
 }
}

users: {
 userID1: {
  name: "vzhen"
 },
 userID2: {
  name: "ITshop"
 }
}

更新

listenForChats(chatsRef) {
    chatsRef.on("value", (chatsSnap) => {
        var chats = [];

        chatsSnap.forEach(chatSnap => {

            this.usersRef.child(chatSnap.val().sellerID).on('value', (userRef) => {
                alert(userRef.val().name);
            })

            chats.push({
                lastMessage: chatSnap.val().lastMessage,
                name: //HOW TO PASS userRef.val() TO HERE?
            })

        })


        //IGNORE THIS LINE - react native thingy
        this.setState({
            dataSource: this.state.dataSource.cloneWithRows(chats)
        });
    })
}

答案

来自vzsg和FrankvanPuffelen this.setState()应在forEach() {}内,否则,没有人会知道您有新数据。

0 个答案:

没有答案
相关问题