说我正在听一个小部件:
const ref = firebase.database().ref(`widgets/${widgetId}`);
ref.on('value', function(snapshot){
console.log(snapshot.val()); // <-- I never see this if ref doesn't exist!
}
如果该小部件不存在,我想了解它。我希望snapshot.val()
返回null
。但问题是功能根本没有运行。所以我无法检查null
的事件。它只是保持沉默。
奇怪的是,这解决了它:
const ref = firebase.database().ref(`widgets/${widgetId}`);
ref.once('value', function(){});
ref.on('value', function(snapshot){
console.log(snapshot.val()); // <-- Now is null!
}
现在,on
提供的功能与snapshot.val()
=== null
一起运行。这是一个错误还是我做错了什么?
答案 0 :(得分:0)
我需要将Firebase升级到最新版本(3.0.5 - > 3.2.0)
npm install --save firebase