【发布时间】:2018-05-07 18:32:26
【问题描述】:
当我执行这段代码时,数组的最后一个元素丢失了,或者为什么?为什么会出现这种情况,会不会是因为它是一个异步函数?
async getRow(){
const user = firebase.auth().currentUser
var itemsRef = Metodos.getRef().child('Amigos/'+user.uid);
itemsRef.on('value', async (snapshot) =>{
let items = [];
childs = snapshot.val();
for(child in childs){
local = await Metodos.getLocal('-Ky7eG2rueIq47GUa7v5');
firebase.database().ref().child('usuario/'+child).on('value', (snap) =>{
datos = snap.val();
items.push({
nombre: datos.nombre,
imagen: datos.imagen
})
})
}
this.setState({
amigos: items
})
});
}
【问题讨论】:
标签: arrays reactjs firebase react-native firebase-realtime-database