다음은 HTTP PUT RESTful 아약스 액세스 및 업데이트 그리드 그리드를위한 완벽한 솔루션입니다.
$.ajax({
type: "PUT",
url: "/api/WebAPIService",
data: $('#editForm').serialize(),
success: function (result) {
if (result) {
var scope = angular.element($("#ngBody")).scope();
var row = scope.gridOptions.selectedItems[0];
var index = scope.myData.indexOf(row);
scope.gridOptions.selectItem(index, false);
scope.$apply(function() {
scope.myData.splice(index, 1); //delete a row from array
});
scope.$apply(function() {
scope.myData.splice(index, 0, result); //add a row to the same index
});
setTimeout(selectARow, 0); //select the the newly added row
function selectARow() {
scope.$apply(function() {
scope.gridOptions.selectItem(index, true);
});
};
}
}
});
아이디어는 "삭제"와 "추가"를 구분해야한다는 것입니다. 이 2 단계를 "scope.myData.splice (index, 1, result);"와 같은 하나의 명령문에 넣는 것이 더 합리적입니다. 그러나 테스트를 거쳤으므로 간단하지 않습니다. 또한 "삭제 및 추가"와 관련된 모든 작업을 완료 한 후에 setTimeout에서 "항목 선택"을 실행하여 실행되도록 보장해야합니다.