AngularJS + Firebase.util。如何在不知道父密钥的情况下访问数据?

时间:2014-09-04 05:07:06

标签: javascript angularjs object firebase

背景:

创建交货时,将在以下位置创建一个条目:

1- DELIVERIES-> COMPANY-> FIREBASEGENERATEDID->送货详情

要允许用户跟踪他们的购买交易,他们会将送货公司和送达的唯一ID添加到他们的个人资料中。

2- USERS-> DELIVERYTRACKING->公司(交货) - > FIREBASEGENERATEDID(从上面的交货产生):TRUE

我可以根据上面的用例使用Firebase.util.intersection返回Firebase引用数组。但是,当绑定到$ scope中的变量时,我无法访问子对象的特定键,尽管我可以将该批次显示给视图。

我已经构建了一个详细的JSFiddle,它可以通过输入更加雄辩地解释这个问题。

JSFiddle Link:http://jsfiddle.net/rwk1/8po8t35q/9/

所需的代码:

<body ng-app="testApp" ng-controller="TestCtrl">
    <div data-ng-repeat="tDelivery in trackedDelivery | orderByPriority">
      <div class="profile-cards">
        <p>{{tDelivery}}</p>
      </div>
    </div>
    <br/><br/>
    <h5>Question: How do I access the individual delivery details i.e. status?</h5>
</body>

'use strict';

var app = angular.module('testApp', [
    'firebase'
]);

控制器:

app.controller('TestCtrl', function($scope, $firebase){

    var fb = new Firebase('https://so0001.firebaseio.com');
    var trackingRef = fb.child('users/Cara/deliveryTracking');
    var trackingFb = $firebase(trackingRef);

    trackingFb.$on('loaded', function(){
        console.log(trackingFb.$getIndex());
    });

    var trackedDeliveryRefArray = [];

    (function(){

      trackingFb.$on('loaded', function(){
            //console.log(trackingFb.$getIndex());
          angular.forEach($firebase(trackingRef ).$getIndex(), function (k,v){
              var trackedDeliveryRef = new Firebase.util.intersection(fb.child('users/Cara/deliveryTracking/' + k ), 
                                                                fb.child('deliveries' + '/' + k ));
              trackedDeliveryRefArray.push($firebase(trackedDeliveryRef));
          });


      });
    })();

    $scope.trackedDelivery = trackedDeliveryRefArray;




});

结果:

{"-randomFBKey1":{"company1":true,"name":"name value 1","status":"delivery 1 status"}}

{"-randomFBKey3":{"company2":true,"name":"delivery 3","status":"delivery 3 status"}}



Question: How do I access the individual delivery details i.e. status?

结构:

Firebase structure

0 个答案:

没有答案