Posted in jQuery onJuly 09, 2018
本文实例讲述了jQuery实现简单复制json对象和json对象集合操作。分享给大家供大家参考,具体如下:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>3water.com jQuery复制json</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> $(function () { var classList = [ { classId: 1, className: '一班', students: [ { studentId: 1, studentName: '张三' }, { studentId: 2, studentName: '李四' } ] }, { classId: 2, className: '二班', students: [ { studentId: 3, studentName: '王五' }, { studentId: 4, studentName: '马六' } ] } ] var classDemo = { classId: 1, className: '一班', students: [ { studentId: 1, studentName: '张三' }, { studentId: 2, studentName: '李四' } ] } var newClassList = jQuery.extend(true, [], classList);//复制对象集合 var newClassDemo = jQuery.extend(true, {}, classDemo);//复制对象 //输出测试: console.log(newClassList); console.log(newClassDemo); }); </script> </head> <body> </body> </html>
使用本站HTML/CSS/JS在线运行测试工具:http://tools.3water.com/code/HtmlJsRun,可得到如下测试运行效果:
jQuery实现简单复制json对象和json对象集合操作示例
- Author -
曹振华声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@