【发布时间】:2014-07-12 10:19:29
【问题描述】:
这是 Plunker:http://plnkr.co/edit/aqLnno?p=preview
我有一个要显示在 ng-grid 中的人员列表 ($scope.persons)。每行都有一个编辑按钮。当用户单击按钮 (ng-click="edit(row)")(参见下面的代码)时,我复制显示的人 (angular.copy(row.entity)) 并打开一个模式对话框。 ...到目前为止一切顺利。
当用户在模式上单击“取消”时,什么也没有发生。当用户在模型上点击“保存”时,修改后的人会被返回,应该在$scope.persons中“重新整合”。
这就是问题的开始:我在$scope.persons 中搜索以找到正确的人并将其替换为从模态返回的人。日志语句显示修改前后的$scope.persons,一切看起来都很好。但是,ng-grid 似乎并不在意。它仍然在不同的(旧的)$scope.persons 上运行。
如果我取消注释 row.entity = person 并直接设置行,那么在 ng-grid 中一切看起来都很好。但是,由于底层数据模型没有正确更改,因此度假村将再次调出旧的(未修改的)人。
这是我的编辑功能的代码:
$scope.edit = function(row) {
$modal.open({
templateUrl: 'personEdit.html',
backdrop: true,
windowClass: 'modal',
controller: 'PersonModalInstanceCtrl',
resolve: {
person: function() {
return angular.copy(row.entity);
}
}
})
.result.then(function(person) {
$log.log('Edited person: ' + JSON.stringify(person));
angular.forEach($scope.persons, function(p, index) {
$log.log('p: ' + JSON.stringify(p) + ' index: ' + index);
if (p.id == row.entity.id) {
$log.log('scope: ' + JSON.stringify($scope.persons));
$scope.persons[index] = person;
}
});
$log.log('scope: ' + JSON.stringify($scope.persons));
// row.entity = person;
}, function() {});
};
我的示波器做错了什么?
感谢您的帮助
【问题讨论】:
-
在插件中找不到按钮
-
编辑按钮位于 personCellTemplate.html 中,它作为附加列包含在 $scope.gridOptions 中的 ColumnDefs 中:{field: 'Actions', cellTemplate: 'personCellTemplate.html'}。但这部分有效:模式打开,可以进行编辑,并且它确实正确返回了编辑后的人。
-
它说的是
ReferenceError: $modal is not defined -
plnkr.co/edit/aqLnno?p=preview 对我有用...(好吧,我可能搞砸了冻结按钮。现在可以工作了吗???)
标签: angularjs angularjs-scope ng-grid