我想过滤一个Firebase路径,看看我的路径中是否存在小孩。
我只想返回值有至少一个路径调用“响应”的值。它的工作原理,但是当路径没有这个孩子,它把我这个错误:
AngularJs过滤函数返回值的错误
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
我用火力地堡-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;
以外的适当方式进行测试?谢谢
为什么不检查孩子的存在并返回(data.responses && data.responses。$ value!== null)? – mhodges