2 回答

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊
????
請(qǐng)記住,實(shí)時(shí)數(shù)據(jù)庫(kù)中的所有內(nèi)容都是鍵:值對(duì)。當(dāng)定義路徑并且您在該路徑中進(jìn)行 .push 時(shí),將創(chuàng)建一個(gè)具有子鍵:值對(duì)的節(jié)點(diǎn),該節(jié)點(diǎn)位于該路徑的“下方”。
如果您查看代碼,您實(shí)際上是在定義數(shù)據(jù)的路徑,最后一個(gè)組件是date
this.db.ref(`organization/${orgId}/visitor-attendance/${date}`).push({[attendeeUid]: true});
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?^^^ path? ? ? ? ? ^^^ key? ?^^^ value
路徑是
organization
? ?orgId
? ? ? visitor-attendance
? ? ? ? ?date
? ? ? ? ? ?the pushID
? ? ? ? ? ? ? ?MNSIxm_woAnBAkVQWRV: true
每次將新子項(xiàng)添加到指定的 Firebase 引用時(shí),push() 方法都會(huì)生成一個(gè)唯一的密鑰。
一種可能的解決方法是使用 .set,
對(duì)于基本寫(xiě)入操作,您可以使用 set() 將數(shù)據(jù)保存到指定的引用,替換該路徑上的任何現(xiàn)有數(shù)據(jù)。
firebase.database().ref('users/' + userId).set({
? ? username: name,
? ? email: email,
? ? profile_picture : imageUrl
? });

TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊
上面的評(píng)論和回答非常有幫助。我最終通過(guò)更改為解決了這個(gè)push
問(wèn)題update
。
現(xiàn)在代碼如下:
setVisitorAttendanceDate = (orgId, attendeeUid, date) => this.db.ref(`organization/${orgId}/visitor-attendance/${date}`).update({[attendeeUid]: true});
添加回答
舉報(bào)