【发布时间】:2013-09-28 01:51:07
【问题描述】:
我开发了提供基本 CRUD 功能的简单 angular-firebase 应用程序。
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 方法。我已经访问了 firebase 的文档,所以我得到了运行良好的波纹管代码。
var current = new Firebase('https://myurl/employee/-J48go0dwY5M3jAC34Op');
current.onDisconnect().remove();
但我想动态创建它,所以如何获取当前节点的父 ID,如 -J48go0dwY5M3jAC34Op ?
请帮我解决小问题。
【问题讨论】: