我在一个vuex存储中有一个firebase文档列表,并且这个列表会被动态更新。我想用vuexfire动态绑定列表中的文档。
state: {
docsToBind: [], // dynamic: this gets updated so I cannot hardcode a few bindings
documents: {} // bind documents here?
},
actions:{
bindOne: firestoreAction(({ state, bindFirestoreRef }) => {
return bindFirestoreRef(...)
}),
bindAll({state}){
for(const doc of state.docsToBind){
// bind the document to a dictionary item?
},
unbindTeam({state}){
// whenever a doc is removed from the listunbind it
}
}这样做对吗?
备注:我不能绑定整个集合,因为客户端没有访问所有文档的权限。所以我需要绑定docsToBind中的子集
发布于 2020-09-01 13:48:15
使用Vuexfire时,当您绑定时,您应该只提供要绑定的状态和源(集合、查询或文档)的键。
因此,如果要绑定到集合的子集,则需要绑定到Query,因此需要知道查询定义(即子集的定义)。
如果要在“一个操作”中绑定一组文档(定义是动态的,例如,通过in的变量列表标识的一组文档),则可能需要使用另一种方法。
例如,您可以定义查询,方法是在文档中有一个带有ID的字段,并使用in操作符将同一字段上最多10个相等(==)子句与逻辑OR组合起来。
或者,您需要创建您自己自制的绑定,例如在Vuex操作中使用Promise.all()。
https://stackoverflow.com/questions/63685473
复制相似问题