本文介绍了AngularFire - 删除单个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我认为的相关代码:
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}}
单击复选框时,我希望从数据库中删除 todos
数组中的相应对象.
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-repeat
循环时,在todos 中使用(id, t)
.这允许您将 id
作为参数发送到 ng-click
函数,而 $scope.todos.$remove(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 - 删除单个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!