2017-07-15 47 views
1

我在onDelete()firebase雲功能中獲得null值。以下是我的代碼在Firebase雲功能中獲取null值onDelete()

exports.jobSeekerToES=functions.database.ref('/Users/{userId}/userFileDetails/files/{fileKey}').onDelete(event=> 
{ 

var file=event.data.val(); 
console.log("deleted file key"+event.params.fileKey); 
console.log("deleted file "+file); // file is null 

}); 

它在日誌上打印fileKey。但文件是空 請幫我在哪裏,我錯了

回答

10

event.data.val()返回位置刪除後的值。對於onDelete()觸發器,它始終爲空。要獲取值刪除使用事件快照的previous屬性之前:

exports.jobSeekerToES=functions.database.ref(
    '/Users/{userId}/userFileDetails/files/{fileKey}').onDelete(event=> 
{ 

    var file=event.data.previous.val(); // <= CHANGED 
    console.log("deleted file key"+event.params.fileKey); 
    console.log("deleted file "+file); 

}); 
+0

日Thnx @Bob星達 – FaisalAhmed

+0

真正有用的帖子! – Lucy