我有一个由ng-grid加载的任务项网格,当点击加载Modal窗口中的更多信息时,用户单击Submit然后在DB中将任务设置为inactive,我需要从Grid中删除它。
我的控制器:
app.controller('taskController', ['$scope', 'myTasks', 'modalService',
function($scope, myTasks, modalService) {
$scope.loading = true;
// Init Grid
$scope.myData = [];
$scope.mySelections = [];
$scope.gridOptions = {
data: 'myData',
columnDefs: [{field: 'headline', displayName: 'Headline', cellTemplate:'<div class="ngCellText" ng-class="col.colIndex()"><a class="selectedItems" ng-click="edit(row)">{{row.getProperty(col.field)}}</a></div>'},
{field:'date_assigned', displayName:'Date'}],
selectedItems: $scope.mySelections,
multiSelect: false,
headerRowHeight:0,
headerCellTemplate: '',
hideHeaders: true,
enableRowSelection: true
};
// Fetch tasks and populate grid
$scope.tasks = myTasks.myTasks().then(function(tasks) {
$scope.myData = tasks;
$scope.gridOptions = { data: 'myData' }
$scope.loading = false;
// Open model when row clicked
$scope.edit = function (row, $scope) {
var modalOptions = {
closeButtonText: 'Cancel',
actionButtonText: 'Update Task',
headerText: 'View Task',
headlineText: row.entity.headline,
messageText: row.entity.message,
assignedToText: row.entity.assigned_to_name,
assignedByText: row.entity.assigned_by_name,
dateAssignedText: row.entity.date_assigned
};
// Open modal with task details
modalService.showModal({}, modalOptions).then(function (result) {
var status = $('#task_status').is(':checked');
var message = $('#completed_message').val();
var xsrf = $.param({id: row.entity.id, status: status, message: message});
// Update task and reload grid
myTasks.updateTask(xsrf).then(function(row) {
// Remove item from grid - NOT WORKING HERE
var index = this.row.rowIndex;
alert(index);
$scope.gridOptions.selectItem(index, false);
$scope.myData.splice(index, 1);
});
});
};
});
}]);
更新:从$ scope.myData中删除项目
答案 0 :(得分:0)
您应该从$ scope.myData而不是$ scope.items中删除该项,因为它是您绑定网格的内容。