使用angularFire(v2)通过唯一ID获取节点

时间:2013-12-13 23:28:38

标签: firebase angularfire

我有一个简单的问题,我似乎正在努力。我正在构建一个简单的锻炼跟踪器,我正在尝试添加锻炼。我正在使用Date.now()定义锻炼的唯一ID,以及类似的内容:

  // get the overall ref to the Firebase
  $scope.workouts = $firebase(new Firebase("https://robus.firebaseio.com/workouts"));

  $scope.addWorkout = function() {    
    var newWorkout = $firebase(new Firebase("https://robus.firebaseio.com/workouts/" + id));
    newWorkout.$set({
      id: Date.now();,
      name: this.workoutName,
    });

    this.workoutName = "";
  },

这很有效。我的Firebase树中的节点看起来像:

http://dl.dropbox.com/u/68704/Screenshots/xrev.png http://dl.dropbox.com/u/68704/Screenshots/xrev.png

虽然这对我来说似乎有点多余。我正在存储id,因为我无法弄清楚如何“获取”节点。我必须使用$child吗?我尝试过这样的事情:

console.log(newWorkout.$child('1386976952038'));我总是遇到TypeError: Cannot call method 'ref' of undefined错误。

0 个答案:

没有答案
相关问题