我用过编辑按钮.编辑后,我有保存和取消按钮.save按钮正在按预期工作但不是取消按钮.
如果我在尝试编辑后单击取消按钮,它应该显示以前的文本.谁能帮帮我吗
js在这里摆弄 http://jsfiddle.net/F7K63/143/
如果我在尝试编辑后单击取消按钮,它应该显示以前的文本.谁能帮帮我吗
js在这里摆弄 http://jsfiddle.net/F7K63/143/
<tr ng-repeat="item in items"> <td> <span ng-hide="item.editing">{{item.name}} <button ng-click="editItem(item)">Edit</button></span> <input ng-show="item.editing" ng-model="item.name" autofocus /> <button ng-show="item.editing" ng-click="doneEditing(item)">Save</button> <button ng-show="item.editing" ng-click="Cancel(item)">Cancel</button> </td> </tr>
制作要编辑的对象的副本.如果按取消,请更换原点.见
fiddle
原文链接:https://www.f2er.com/angularjs/142205.html$scope.editItem = function (item) { item.editing = true; item.backupName = angular.copy(item.name); } $scope.doneEditing = function (item) { item.editing = false; delete item.backupName; //do some background ajax calling for persistence... }; $scope.Cancel = function (item) { item.editing = false; item.name = angular.copy(item.backupName); delete item.backupName; };