首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >滤波函数返回值中的AngularJs误差

滤波函数返回值中的AngularJs误差
EN

Stack Overflow用户
提问于 2016-08-22 17:08:19
回答 1查看 54关注 0票数 0

我想过滤一个Firebase路径,看看我的路径中是否存在一个子路径。

我只想返回有路径调用"reponses“的值。它可以工作,但是当路径没有这个孩子时,它会抛给我这个错误:

代码语言:javascript
复制
    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是这样的:

代码语言:javascript
复制
    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; 之外,如何才能以正确的方式进行测试呢?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-22 17:13:32

听起来像data.responsesundefined,所以您可以这样检查$value

代码语言:javascript
复制
.filter(function (data, key, priority) {
    return data.responses && data.responses.$value !== null;
}).ref();

这确保在探测responses字段之前,data上有一个$value字段。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39085093

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档