我想过滤一条 Firebase 路径,看看我的路径中是否存在一个孩子。
我只想返回具有路径调用“响应”的值。它可以工作,但是当路径没有这个孩子时,它会给我这个错误:
firebase.js:283 Uncaught TypeError: Cannot read property '$value' of
firebase.js:276 FIREBASE WARNING: Exception was thrown by user callback.
TypeError: Cannot read property '$value' of undefined
我像这样使用 Firebase-util 和 Angularfire:
var ref = firebase.database().ref();
var nc = new firebase.util.NormalizedCollection(
ref.child('accounts/' + $localStorage.accountId + '/demandes'),
[ref.child('demandes'), 'widget2']).select('widget2.duree', 'widget2.derniere_modification', 'widget2.reponses', 'widget2.exp', 'widget2.ajout_le', 'widget2.localisation').
filter(function(data, key, priority) {
return data.reponses.$value !== null; // This cause problems !
}).ref();
$scope.items = $firebaseArray(nc);
我该怎么做才能以正确的方式进行测试return data.reponses.$value !== null;
?谢谢