有沒有辦法將 $scope 資料添加到另一個 $scope 而不更改添加它的值?目前,我創建了一個按鈕,每當有人單擊它時,都會執行以下操作。
$scope.updateShiftSummary = function () {
$scope.shiftModalSummary = $scope.shiftSummary;
$('#updateShiftModal').modal('show');
};
由于我正在進行更新,并且每當有人在執行操作后添加班次時,但如果有人在不保存表單的情況下關閉模式,$scope.shiftSummary 也會被更新并且新資料也會被推送到其中,所以如何更新 $scope .shiftModalSummary 僅不影響 $scope.shiftSummary 中的資料
$scope.addShift = function () {
var shiftSummary = $scope.shiftModalSummary;
var totalShifts = shiftSummary.length;
var lastShift = shiftSummary[totalShifts - 1].shiftName.split(" ");
var shiftValue = parseInt(lastShift[1]) 1;
var shiftTime = new Date(new Date().setHours(0, 0, 0, 0));
shiftSummary.push({
'shiftName': 'Shift ' shiftValue,
'startTime': shiftTime,
'endTime': shiftTime,
'staffName': 'Owner'
});
};
uj5u.com熱心網友回復:
$scope.updateShiftSummary = function () {
$scope.shiftModalSummary = angular.copy($scope.shiftSummary); <---
$('#updateShiftModal').modal('show');
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/428401.html
