各行に編集ボタンが含まれているグリッドがあります。最初はページが読み込まれたときにすべてが正常に動作しますが、新しいエンティティを追加してグリッドを再投入しようとすると、編集ボタンは既存の最初のエンティティの編集イベントを発生させます。データ更新後に行ごとに削除されないAngularjs UIグリッドイベント
これは私のコードです:
var columnDefs = [
{
name: '', field: 'id',
cellTooltip: 'Edit',
enableSorting: false,
enableColumnMenu: false,
enableCellEdit: false,
maxWidth: 30,
headerCellTemplate: '<div class="ui-grid-cell-contents ui-grid-icon"></div>',
cellEditableCondition: false,
cellTemplate: '<div class="ui-grid-cell-contents ui-grid-icon"><div title="Edit" class="ui-edit ui-grid-icon-pencil" ng-click="grid.appScope.editNews({{row.entity.id}})"></div></div>'
},
{ name: 'shortDescription', field: 'shortDescription' }];
$scope.gridOptions = {
enableGridMenu: false,
enableSorting: false,
enableRowHashing: false,
columnDefs: columnDefs,
data: "data",
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
}
};
var getData = function() {
showLoading('.grid');
newsRepository.resourceFunctions.query(displayOptions,
function (data) {
if (data.length == 0) {
setEmptyGrid($scope, 'There are no news!');
$scope.data = [{
"message": 'There are no news!'
}];
}
else {
setGrid(data);
}
hideLoading('.grid');
}, //success
function (error) {
$scope.gridApi.selection.clearSelectedRows();
hideLoading("#view-container");
toaster.pop('error', "Server error",
"There was an error while processing your request. Please contact support.", 10000);
}); //error
};
function setGrid(data) {
$scope.gridOptions.columnDefs = columnDefs;
$scope.data = data;
}
これは(データはAJAXリクエストを保存するから来ている)グリッドが再人口がどのようである:
$scope.gridApi.selection.clearSelectedRows();
setGrid(data.items);
編集イベントが内側にありますcellTemplate:grid.appScope.editNews({{row.entity.id}})。また、グリッドデータが更新された後、このテンプレートには正しいエンティティIDが設定されますが、古いエンティティのIDを使用してeditNewsが呼び出されます。どのように私はこれを修正することができる任意のアイデア?