我开发了简单的 Angular-Firebase 应用程序,它提供基本的 CRUD 功能。
firebase 中的 json 格式
{
"-J0wuZ_J8P1EO5g4Xfw6" : {
"contact" : "56231545",
"company" : "info",
"city" : "limbdi",
"name" : "priya"
},
"-J0wrhrtgFvIdyMcSL0x" : {
"contact" : "65325422",
"company" : "rilance",
"city" : "jamnagar",
"name" : "pihu"
}
}
用于列出 html 页面中所有数据的角度代码
<table class='table table-hover'>
<tr>
<th>Name</th>
<th>City</th>
<th>Company</th>
<th>Contact</th>
<th></th>
</tr>
<tr ng-repeat="item in employee">
<td>{{item.name}}</td>
<td>{{item.city}}</td>
<td>{{item.company}}</td>
<td>{{item.contact}}</td>
<td><button class='btn btn-warning btn-mini' ng-click='delemp(employee[$index])'>X</button></td>
</tr>
</table>
当有人单击按钮时,它会触发 delemp 函数,该函数将员工的当前索引作为参数。
var myapp = angular.module('myapp',['firebase']);
myapp.controller('MyCtrl', ['$scope', 'angularFireCollection',
function MyCtrl($scope, angularFireCollection) {
$scope.delemp=function($current_emp){
alert($current_emp.name);
};
}
]);
该警报框包含当前员工的姓名。我想删除当前行的员工。但我不知道如何使用remove()
火力基地的方法。我访问了 firebase 的文档,所以我得到了运行良好的以下代码。
var current = new Firebase('https://myurl/employee/-J48go0dwY5M3jAC34Op');
current.onDisconnect().remove();
但我想动态地创建它,那么如何获取当前节点的父ID,例如-J48go0dwY5M3jAC34Op
?
请帮我解决小问题。