Jay*_*inh 4 angularjs firebase
我开发了简单的angular-firebase应用程序,它提供了基本的CRUD功能.
firebase中的json格式
{
"-J0wuZ_J8P1EO5g4Xfw6" : {
"contact" : "56231545",
"company" : "info",
"city" : "limbdi",
"name" : "priya"
},
"-J0wrhrtgFvIdyMcSL0x" : {
"contact" : "65325422",
"company" : "rilance",
"city" : "jamnagar",
"name" : "pihu"
}
}
Run Code Online (Sandbox Code Playgroud)
用于列出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>
Run Code Online (Sandbox Code Playgroud)
当有人点击按钮时,它会触发删除功能,该功能将员工的当前索引作为参数.
var myapp = angular.module('myapp',['firebase']);
myapp.controller('MyCtrl', ['$scope', 'angularFireCollection',
function MyCtrl($scope, angularFireCollection) {
$scope.delemp=function($current_emp){
alert($current_emp.name);
};
}
]);
Run Code Online (Sandbox Code Playgroud)
此警报框包含当前员工的姓名.我想删除当前的员工行.但我不知道如何使用remove()
firebase的方法.我已经访问了firebase的文档,所以我得到了波纹管代码,它工作得很好.
var current = new Firebase('https://myurl/employee/-J48go0dwY5M3jAC34Op');
current.onDisconnect().remove();
Run Code Online (Sandbox Code Playgroud)
但我想动态地制作它,那么如何获得当前节点的父ID -J48go0dwY5M3jAC34Op
呢?
请帮我弄清楚小问题.
Jef*_*lse 12
您可以将id传递给删除功能,而不是传递对象.
<li ng-repeat="(key,item) in list">
<button ng-click="deleteItem(key)">delete</button> {{item.name}}
</li>
$scope.deleteItem = function(id){
var itemRef = new Firebase(url + '/' + id);
itemRef.remove();
}
Run Code Online (Sandbox Code Playgroud)
编辑:这也有效
<div ng-repeat="item in list">
<button ng-click="writeID(item)">log id</button>{{item.$id}} {{item}}<hr>
</div>
$scope.writeID = function(o){
console.log(o.$id);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6174 次 |
最近记录: |