码迷,mamicode.com
首页 > 其他好文 > 详细

1009日重点: 深复制

时间:2017-10-09 16:42:42      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:wro   name   uri   nbsp   new   ati   tin   string   fun   

//深复制
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日重点: 深复制

标签:wro   name   uri   nbsp   new   ati   tin   string   fun   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!