首页 > 其他 > 详细

1009日重点: 深复制

时间:2017-10-09 16:14:36      阅读:220      评论:0      收藏:0      [点我收藏+]
//深复制
var deepCopy= function(source) {
var result={};
for (var key in source) {
result[key] = typeof source[key]===‘object‘? deepCopy(source[key]): source[key];
}
return result;
}

function serializeData( data ) {
// If this is not an object, defer to native stringification.
if ( ! angular.isObject( data ) ) {
return( ( data == null ) ? "" : data.toString() );
}
var buffer = [];
// Serialize each key in the object.
for ( var name in data ) {
if ( ! data.hasOwnProperty( name ) ) {
continue;
}
var value = data[ name ];
buffer.push(
encodeURIComponent( name ) + "=" + encodeURIComponent( ( value == null ) ? "" : value )
);
}
// Serialize the buffer and clean it up for transportation.
var source = buffer.join( "&" ).replace( /%20/g, "+" );
return( source );
};
 
 
 
 
 
引用:
 
$scope.newrow = deepCopy(data);

1009日重点: 深复制

原文:http://www.cnblogs.com/bettynie/p/7641498.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!