从child_removed firebase事件中获取已删除项的密钥

时间:2016-01-21 08:22:54

标签: firebase

是否可以在Firbase的on('child_removed')回调函数中检索已删除子项的密钥?

2 个答案:

答案 0 :(得分:9)

来自Firebase documentation for on('value'

  

每次移除儿童时都会触发此事件一次。传递给回调的DataSnapshot将是已删除子项的旧数据。

firebaseRef.on('child_removed', function(oldChildSnapshot) {
  console.log('Child '+oldChildSnapshot.key()+' was removed');
});

答案 1 :(得分:0)

已接受的答案对我不起作用,但确实如此:

firebaseRef.on('child_removed', function(oldChildSnapshot) {
  console.log('Child '+oldChildSnapshot.key+' was removed');
});

使用.key代替.key()