[英]How get the id of an document from vuejs and firestore?
我有這個代碼可以從 firestore 獲取所有文件:
const getThemesList = async ({ commit }) => {
const snapshot = await firebase
.firestore()
.collection('themes')
.get();
const promiseThemes = snapshot.docs.map(doc => doc.data());
commit(types.GET_THEMES, promiseThemes);
};
通過我可以列出的功能,每個項目都有一個刪除按鈕:
<v-btn text @click="deleteTheme(item)">
Delete
</v-btn>
每個項目只有這些參數:
{
description: (...)
name: (...)
type: (...)
}
但是,如果我沒有他們的 ID,我該如何刪除項目?
db.collection('themes')
.doc(theme.id)
.delete()
.then(function() {
我怎樣才能得到身份證? 主題.id?
編輯 1:我對@DougStevenson 的回答有疑問
doc
是一個具有id
屬性的DocumentSnapshot 。 只需將文檔 ID 添加到您生成的每個項目對象中:
const promiseThemes = snapshot.docs.map(doc => {id: doc.id, ...doc.data());
現在您有一個帶有id
屬性的對象,您可以使用它來刪除文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.