【发布时间】:2016-07-03 18:13:05
【问题描述】:
下面的代码使用once('value') 按索引检索用户的联系人列表。那么如果有人更改description,我的联系人列表将不会实时更新,因为它是once()。我不能使用on(),因为这会导致疯狂的查询泄漏。那么我应该在哪里放置on('child_added') 来监听每个节点。
getContacts(userID) {
var contactList = [];
this.ref.child('userContacts').child(userID).once('value', (contacts) => {
contacts.forEach((contact) => {
this.ref.child('users').child(contact.key()).once('value', (contact) => {
contactList.push({
key: contact.key(),
name: contact.val().name,
description: contact.val().description,
numberOfProduct: contact.val().numberOfProduct
});
this.setState({
dataSource: this.state.dataSource.cloneWithRows(contactList)
});
})
})
})
}
【问题讨论】:
标签: javascript firebase react-native firebase-realtime-database