1
请告诉,如何把数据放回队列返回数组。由于组件渲染速度比firebase快,因此发送数据。如何从firebase存储获取react.js的异步图像数据?
来自此代码的片段(终极版的)
function fetchPosts(key) {
return dispatch => {
dispatch(requestPosts(key))
return database.ref('article/').once('value', snap => {
let childData = []
snap.forEach(function(child) {
getImage(child.val().thumb).then((url) => {
console.log(url)
return {
"id": child.key,
"url": url,
...child.val()
}
}).then((array) => {
console.log(array)
childData.push(array)
})
})
dispatch(receivePosts(key, childData))
})
.catch((error) => {
console.log(error)
dispatch(receivePosts(error))
})
}
}