加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – AngularFire – 删除单个项目

发布时间:2020-12-17 06:55:30 所属栏目:安全 来源:网络整理
导读:以下是我视图中的相关代码: p(ng-repeat="t in todos")input( type="checkbox",ng-model="t.done",ng-click="clearItem($event)" ){{t.text}} done? {{t.done}} 单击该复选框时,我希望从数据库中删除todos数组中的相应对象. 我的clearItem函数如下: $scope
以下是我视图中的相关代码:

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

单击该复选框时,我希望从数据库中删除todos数组中的相应对象.

我的clearItem函数如下:

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

但是,这会删除我的数据库中的所有条目.我希望它只删除有问题的特定对象.反正我还能这样做吗?

解决方法

好吧,想通了.

使用ng-repeat循环时,在待办事项中使用(id,t).这允许您将id作为参数发送到ng-click函数,$scope.todos.$remove(id)工作得很好.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读