【发布时间】:2019-10-25 09:33:08
【问题描述】:
我正在尝试从我遇到的某个用户的每个集合的子集合中获取文档。我有一个存储操作,它首先获取列表,然后在 forEach 循环中传递给第二个操作以构建状态。但是当它执行该操作时,我收到一个错误,即 getCollections 不是函数。
getCollections 有什么变化还是我的代码有问题?
谢谢
// ###########################################
// ############# Lists #######################
async usersLists({ commit, state }) {
let listsData = [];
// Check if a user is logged in.
if (state.user) {
await db
.collection('lists')
.where('list_owner', '==', state.user.uid)
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
listsData.push({
id: doc.id,
...doc
});
// Commit the state.list.id and pass off to getListAddons
console.log('setListId: ', doc.id);
this.commit('setListId', doc.id);
this.dispatch('getListAddons');
});
commit('usersLists', listsData);
})
.catch(err => {
console.log('Error getting documents', err);
});
} else {
commit('usersLists', null);
}
},
async getListAddons({ commit, state, dispatch }) {
console.log('state of listid: ', state.setListId);
await db
.collection('link')
.doc(state.setListId)
.getCollections()
.then(collections => {
collections.forEach(collection => {
console.log('Found subcollection with id:', collection.id);
});
})
.catch(err => {
console.log('Error getting documents', err);
});
}
【问题讨论】:
标签: javascript google-cloud-firestore vuex nuxt.js