我需要复制一个对象并在将其发送到服务器之前执行一些过滤。在这个例子中,我需要删除两个数组属性。但是,当我从复制的对象中删除数组属性时,它们也会从原始对象中删除。删除引用的正确方法是什么?
// Copy object to master for use as a backup
$scope.master = angular.copy($scope.user);
return $http( {method: 'PUT',
url: config.serviceBaseUri_v3 + $rootScope.permissions.PutUsers.uri.replace("{userId}", data.id),
data: $.param(filterPutRequest(angular.copy(data))),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}});
// Remove unwanted properties from the server request
var filterPutRequest = function(user){
if($rootScope.permissions.PutUsers.fields){
var propNames = Object.getOwnPropertyNames(user);
for(var i=0;i<propNames.length;i++){
if($rootScope.permissions.PutUsers.fields.indexOf(propNames[i]) === -1){
delete user[propNames[i]];
}
}
}
return user;
};