firebase获取id for for delete

时间:2013-12-26 04:59:26

标签: json angularjs firebase

如何在firebase中逐项删除或更改?我需要为基数中的所有行添加id字段?找到的所有示例都显示了如何在id对象字段的控制台中输出id。

<div class="well span8" id="messagesDiv">

    <div class="well span3 pull-left note" ng-repeat="msg in messages">
        <button type='button' class='close' ng-click="deleteItem( msg )">×</button>
        <b>
        {{msg.time| date: 'longDate'}}
        </b>
        <br>{{msg.title}}
        <br>{{msg.body}}
    </div>
</div>

1 个答案:

答案 0 :(得分:4)

除了值之外,您还需要获取对象的键,然后将它们传递给$remove方法:

<div class="well span3 pull-left note" ng-repeat="(key, msg) in messages">
  <button type='button' class='close' ng-click="messages.$remove(key)">×</button>
  ...
</div>

当然假设messages是$ firebase的一个实例(由angularFire提供):

$scope.messages = $firebase(new Firebase(URL));