我使用Firebase数据库,我有一张卡片列表,如果删除它们,我需要监控一些卡片。我尝试用ref.observe (.childRemoved)
执行此操作,但这不适用于我的情况,因为持卡人可以删除某些数据,然后此块会触发几次,我需要查看整个卡是否已被删除。我怎么能这样做?
我的参考
let ref = FIRDatabase.database().reference().child(MainGateways.cards.rawValue).child(card.id)
我的卡片结构
"cards": {
"-Khv9rUVwErNHBzXcruO": {
"additionalInfo": {
"note": ""
},
"dateProperties": {
"day": "Flex",
"isFlexDate": true,
"isFlexTime": true,
"iso8601": "",
"time": ""
},
"interestedUsers": {
"NfM26A2YcPUFz8rfYa23Kr3mjCO2": {
"isApproved": false,
"isNew": true,
"isoDate": "2017-04-17T13:08:41+04:00",
"userID": "NfM26A2YcPUFz8rfYa23Kr3mjCO2",
"userItchableName": "Alexsander K."
}
},
"isNewPendingRequest": true,
"isPrivateStatus": false,
"isTest": false,
"ownerID": "1Cix149ThIOG1ULPVjyy0LyTxbe2",
"peopleProperties": {
"availableSeats": 1,
"numberOfPeople": 1,
"numberOfPeopleDescription": "1 person"
},
"title": "Genius Lounge and Sake Bar",
"userName": "Tim C.",
"version": 1
},
我也试图建立这样一个链接,但是如果从列表中删除了任何卡,那么这个块就可以工作。
guard let ref = FIRDatabase.database().reference().child(MainGateways.cards.rawValue).child(card.id).parent else { return }
答案 0 :(得分:1)
查看Cloud Functions for Firebase。使用它,您可以编写JavaScript代码,以响应您指定的路径中的数据库更改。这允许您编写独立于客户端应用程序的逻辑来响应数据库中的更改。