【发布时间】:2018-08-12 03:06:05
【问题描述】:
在 React Native 上使用 Firestor。
我收到此错误:
错误:Query.get 失败:第一个参数必须是对象
当我尝试从其他集合(项目)中获取用户数据时,这不起作用。
export const itemsFetch = () => {
return (dispatch) => {
firebase.firestore().collection('items').get()
.then((snapshot) => {
const items = snapshot.docs.map(doc => doc.data());
return items
})
.then((items) => {
const userPromises = items.map((item, itemId) => {
const userId = item.userId;
console.log('userId: ', userId);
return firebase.firestore().collection('users').get(userId)
.then((snapshot) => {
console.log('snapshot:', snapshot);
const user = snapshot.docs.data();
return user;
console.log('user:', user);
})
.then(user => ({...item, user: user, itemId}));
});
dispatch({ type: 'ui/loading/hide' });
return Promise.all(userPromises);
})
};
};
我可以获取数据snapshot,但我仍然无法实现。
【问题讨论】:
标签: javascript reactjs firebase google-cloud-firestore