1
我正在開發我的第一個小型AngularFire/AngularJs應用程序。我想使用Angular-xeditable插件。 到目前爲止,我可以創建並保存新的數據,但我無法找到如何使用Angular-xeditable更新現有數據。使用Angularfire和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})會發生什麼。 – Kato 2014-10-13 18:25:48
是的,我想執行「save」。我在這裏閱讀了關於索引(https://www.firebase.com/docs/web/libraries/angular/guide.html),但我不知道如何使用它來保存特定的記錄。 – 2014-10-13 21:10:18