【发布时间】:2020-12-20 10:32:00
【问题描述】:
我在 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中绑定子集
【问题讨论】:
-
我不清楚你到底想要达到什么目的。使用 Vuexfire,当您绑定时,您应该只提供要绑定的状态键和源(集合、查询或文档)。因此,如果您想绑定到集合的子集,则需要绑定到 Query,因此您需要知道 Query 定义(即子集的定义)。
-
谢谢你的答案。那么查询绑定到集合中的多个文档是什么?这就是我在文档中找不到的内容。
-
你想如何查询这个集合?基于特定领域?
-
我想绑定到一个文档列表,所以我有一个文档ID列表。 myCollection.doc(id1), ..., myCollection.doc(idn)
-
不,但我想我必须解决这个问题。你应该把它变成一个答案:)
标签: javascript firebase vue.js google-cloud-firestore vuexfire