0
使用角度我創建了一個主題應用程序。它具有重置主題功能,這將允許用戶將主題重置爲更早。以下是我的角碼。我在同一範圍內創建了2個json變量 - currentTheme
和defaultTheme
。 currentTheme被綁定以形成元素,使用該元素用戶可以修改各種屬性的值。作爲默認json的角度商店響應
var ThemeApp = angular.module('ThemeApp', []);
ThemeApp.controller('ThemeCtrl', ['$scope', '$http', function ($scope, $http) {
$http.get("javascripts/myTheme.json").success(function(data) {
$scope.defaultTheme = data;
$scope.currentThemes = data;
console.log($scope.defaultTheme[0]);
});
$scope.saveTheme = function() {
...
};
$scope.resetTheme = function() {
console.log($scope.defaultTheme);
$scope.currentThemes = $scope.defaultTheme;
};
}]);
當我們改變表單字段,則defaultTheme
JSON也得到改變的值。我可以從resetTheme
函數的控制檯聲明中觀察到這一點。我也嘗試將defaultTheme
作爲全局變量,但它也會發生變化。有針對這個的解決方法嗎?
你能改說你的問題嗎?目前還不清楚你想達到什麼目標。 – 2014-09-25 12:34:32
它們都是相同的對象引用。如果您不希望它們引用相同的對象/數組,請進行復制 – charlietfl 2014-09-25 12:54:32