本文介绍了如何使用角度来删除火力JSON数据对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了简单角火力应用程序,它提供了基本的CRUD功能。

I have developed simple angular-firebase application which provide basic CRUD functionality.

在火力JSON格式

{
  "-J0wuZ_J8P1EO5g4Xfw6" : {
    "contact" : "56231545",
    "company" : "info",
    "city" : "limbdi",
    "name" : "priya"
  },
  "-J0wrhrtgFvIdyMcSL0x" : {
    "contact" : "65325422",
    "company" : "rilance",
    "city" : "jamnagar",
    "name" : "pihu"
  }
}

angular- code在HTML页面中列出了所有数据

angular-code for listing all data in html page

<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内搭员工目前的指数作为参数的功能。

when someone click on button it fire delemp function which take employee's current index as argument.

var myapp = angular.module('myapp',['firebase']);
myapp.controller('MyCtrl', ['$scope', 'angularFireCollection',
  function MyCtrl($scope, angularFireCollection) {

       $scope.delemp=function($current_emp){
          alert($current_emp.name);
    };
  }
]);

此警告框包含现有员工的名字。我想删除员工当前行。但我不知道如何使用删除()火力的方法。我曾参观过的火力文件,所以我就怒吼code这是工作不错。

this alert box contain current employee's name. I want to delete current row of employee. but I don't know how to use remove() method of firebase. I have visited documentation of firebase so I got bellow code which is working nice.

var current = new Firebase('https://myurl/employee/-J48go0dwY5M3jAC34Op');
        current.onDisconnect().remove();

但我要使它动态,所以我怎么能得到当前节点的父ID喜欢 -J48go0dwY5M3jAC34Op

请帮我找出小问题。

推荐答案

而不是传递对象,你可以只通过将ID为您删除功能。

instead of passing the object, you could just pass the id into your delete function.

<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();
}

编辑:
这也适用

edit:this also works

<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);
}

这篇关于如何使用角度来删除火力JSON数据对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 01:27