如何在 Angular Smart Table 中编辑整个项目(json 对象)?请参阅下面的我正在尝试做的片段,请注意该对象可以有更多的属性,这就是为什么我称这种方法“乏味”并且更喜欢更简单的方法。活生生的例子: 例子
我是否还需要将 设置newItem
为 中的相应项目displayedItems
?希望不是 b/c 感觉像是一种解决方法。
var app = angular.module('plunker', ['smart-table']);
app.controller('MainCtrl', function($scope) {
$scope.rawItems = [{ title: 'blue' }, { title: 'green' }];
$scope.displayedItems = [].concat($scope.rawItems);
$scope.editTediousButWorks = function(e, index) {
e.preventDefault();
var item = $scope.rawItems[index];
var newTitle = prompt("What is new value?", item.title);
var newItem = { title: newTitle };
item.title = newTitle;
};
$scope.editSimpleButBroken = function(e, index) {
e.preventDefault();
var item = $scope.rawItems[index];
var newTitle = prompt("What is new value?", item.title);
var newItem = { title: newTitle };
item = newItem; // if you look at the rendered rows, nothing gets updated
};
});
注意:这与这个问题不同,因为我不需要 a contenteditable
,只是想知道如何进行基本更新。