AngularFire - 删除单个项目 [英] AngularFire - Remove Single Item

查看:134
本文介绍了AngularFire - 删除单个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是在我看来,有关code:

Here is the relevant code in my view:

p(ng-repeat="t in todos")
input(
    type="checkbox",
    ng-model="t.done",
    ng-click="clearItem($event)"
    )
{{t.text}} done? {{t.done}}

当点击该复选框,我想在待办事项数组中适当的对象从数据库中删除。

When the checkbox is clicked, I want the appropriate object in the todos array to be removed from the database.

我的 clearItem 函数如下:

$scope.clearItem = function(event) {
        todoRef.remove($scope.t);
    }

不过,这会删除我的数据库中的所有条目。我希望它删除有问题只有特定的对象。反正对我来说,做到这一点?

However, this removes all the entries in my database. I want it to remove only the specific object in question. Is there anyway for me to do this?

推荐答案

好了,想通了。

在待办事项中使用 NG-重复,使用(ID,T)循环。这使您可以发送 ID 作为参数传递给 NG-点击功能, $ scope.todos。$删除(ID)作品就好。

When looping using ng-repeat, use (id, t) in todos. This allows you to send id as the parameter to the ng-click function, and $scope.todos.$remove(id) works just fine.

这篇关于AngularFire - 删除单个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆