Firebase $ remove()对使用ref.key()或$ id感到困惑

时间:2015-10-07 14:04:27

标签: firebase angularfire

我正在为帖子列表构建一个非常简单的编辑/删除功能,并使用更新功能:

    $scope.update = function() {
      var fb = new Firebase("https://mydb.firebaseio.com/Posts/" + $scope.postToUpdate.$id);
      var article = $firebaseObject(fb);
      article.Title = $scope.postToUpdate.Title;
      article.Intro = $scope.postToUpdate.Intro;
      article.Body = $scope.postToUpdate.Body;
      article.$save().then(function(ref) {
          console.log($scope.postToUpdate.Title);
        }, function(error) {
        console.log("Error:", error);
    });
}

我认为删除功能几乎相同,即

$scope.deletePost = function() {
        var fb = new Firebase("https://mydb.firebaseio.com/Posts/" + $scope.postToDelete.$id);
        var article = $firebaseObject(fb);
        $scope.postToDelete = article;
        article.$remove().then(function(ref) {
            console.log("removed:" + $scope.postToDelete.Title);
        }, function(error) {
            console.log("Error:", error);
        });
    }

按钮:<button type="button" ng-click="deletePost()">Delete</button>

但没有任何反应。我用firebase ref_key尝试了这个版本,但这仍然没有用

    $scope.deletePost = function() {
        var fb = new Firebase("https://mydb.firebaseio.com/Posts/" + id);
        var id = ref.key();
        var article = $firebaseObject(fb);
        $scope.postToDelete = article;

    article.$remove.then(function(ref) {
        console.log("removed:" + $scope.postToDelete.Title);
    }, function(error) {
        console.log("Error:", error);
    });
}

我一直在阅读一些线程并想知道文章是否应该是一个数组才能删除整个对象?如何定位特定项目以将其删除?

FIXED WITH:article.$remove(article).then(function(ref)但我仍然不明白何时使用ref.key()或$ id(firebase / angularfire?)

0 个答案:

没有答案