与AngularFire 0.5.0 AngularJS - $删除的项目不起作用不起作用、项目、AngularFire、AngularJS

2023-09-14 00:18:26 作者:◇、囡亾忲兲嫃

我只是想更多的工作,我的第一次小角度的项目,我更新AngularFire从0.3.0到0.5.0并没有什么真正的作品了。我能得到的数据库访问回来,还为项目添加到我的名单。但是remove函数不工作了。在我udpated AngularFire,我用剪接(指数1)取一个项目。我也尝试使用新的$ remove从0.5.0但它只是从列表中删除的所有项目,即使我想补充的一个关键。

I just wanted to work more on my first little Angular project and I updated AngularFire from 0.3.0 to 0.5.0 and nothing really works anymore. I was able to get the database access back and also to add items to my list. But the remove function doesn't work anymore. Before I udpated AngularFire, I used splice(index,1) to remove an item. I also tried to use the new $remove from 0.5.0 but it just removes all items from the list, even I add a key.

这就是我的列表重复:

<tr ng-repeat="(key, earning) in earnings | orderByPriority">
    <td>{{earning.date}}</td>
    <td>{{earning.description}}</td>
    <td>{{earning.price}} €</td>
    <td>
      <button class="btn btn-danger" ng-click="removeEarning(key)">
        Löschen
      </button>
    </td>

正如你所看到的,它只是创建了数据的TR和每个项目都有一个删除按钮。当我点击一个特定的项目删除按钮,只有这应该是所有从列表中删除,而不是

As you can see, it just creates a tr with data and each item has a delete button. When I click the delete button on a specific item, only this should be removed and not all from the list.

我现在的JS code:

My JS code now:

function BalanceCtrl($scope, $log, $http, $firebase) {
    var dbEarnings = new Firebase('https://*******.firebaseio.com/Earnings');
    $scope.earnings = $firebase(dbEarnings);

    $scope.addEarning = function() {
        $scope.earnings.$add({date:$scope.FormEarningDate,  description:$scope.FormEarningDescription, price:$scope.FormEarningPrice});    
        $scope.FormEarningDate = '';
        $scope.FormEarningDescription = '';
        $scope.FormEarningPrice = '';
        $scope.updateEarning();}

        $scope.removeEarning = function (key) {
            $scope.earnings.$remove(key);   
        }

它不以某种方式工作,从列表中删除只有特定的项目。这一切都工作得很好用0.3.0。有谁知道我能做些什么?

It doesn't work somehow to remove only the specific item from the list. It all worked fine with 0.3.0. Does anybody know what I can do?

推荐答案

orderByPriority 过滤器收集转换成一个阵列,引起成为数字索引(0,1,2,...) - 它不再是在火力地堡名称。

The orderByPriority filter converts the collection to an array, causing key to become a numeric index (0, 1, 2, …)—it's no longer the Firebase name.

http://angularfire.com/documentation.html :

该orderByPriority滤波器由AngularFire提供一个转换  对象返回了$火力点到一个数组。数组中的对象  按优先级排序(如在火力地堡定义)。此外,每  数组中的对象有一个$ id属性在其上定义,这将  对应于该对象的键名。

The orderByPriority filter is provided by AngularFire to convert an object returned by $firebase into an array. The objects in the array are ordered by priority (as defined in Firebase). Additionally, each object in the array will have a $id property defined on it, which will correspond to the key name for that object.

因此​​,使用 removeEarning(收入。$ ID)

请参阅 http://plnkr.co/edit/pJf2drPwhFAVCuaBSPHq?p=$p $ PVIEW 。