【发布时间】:2014-10-10 16:45:34
【问题描述】:
我正在开发我的第一个小型 AngularFire/AngularJs 应用程序。我想使用Angular-xeditable 插件。 到目前为止,我可以创建和保存新数据,但我找不到如何使用 Angular-xeditable 更新现有数据。
我没有收到错误消息,出了什么问题:
HTML
<table class="table table-hover" ng-controller="premiercontrolleur">
<tr><th>Prénom</th><th>Nom</th></tr>
<tr ng-repeat="client in clients">
<td editable-text="client.prenom" onbeforesave="saveClient($data)">{{client.prenom}}</td>
<td editable-text="client.nom" onbeforesave="saveClient($data)">{{client.nom}}</td>
</tr>
</table>
Javascript
var app = angular.module("crmfirebase", ["firebase", "xeditable"]);
app.run(function(editableOptions) {
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
});
app.controller("premiercontrolleur", function($scope, $firebase) {
var ref = new Firebase("https://mydatabaseurl.firebaseio.com/clients");
var sync = $firebase(ref);
$scope.clients = sync.$asArray();
$scope.addClient = function(client) {
$scope.clients.$add({prenom: client.prenom, nom: client.nom});
}
$scope.saveClient = function(data) {
$scope.clients.$save({prenom: data});
}
});
我尝试了解如何使用此处的保存方法使其工作:https://www.firebase.com/docs/web/libraries/angular/api.html#angularfire-firebasearray-save-recordorindex
【问题讨论】:
-
你在这里传递给 $scope.clients.$save() 什么?它不采用随机数据,它采用记录的索引或记录(它必须已经在数组中)。我无法通过调用 $save({prenom: data}) 来判断您会发生什么
-
是的,我想执行“保存”。我在这里阅读了索引(firebase.com/docs/web/libraries/angular/guide.html),但我不知道如何使用它来保存特定记录。
标签: angularjs firebase angularfire