Backbone.js克隆模型用于创建模型的深层副本或将一个模型对象复制到另一个对象。
句法:
model.clone()
让我们举个例子。
【backbone.js模型克隆clone】请参阅以下示例:
<
!DOCTYPE html>
<
head>
<
title> Model Example<
/title>
<
script src="http://img.readke.com/220416/032412F25-0.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/0324121633-1.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/032412J21-2.jpg" type="text/javascript"><
/script>
<
script type="text/javascript">
var Person= Backbone.Model.extend();
var person=new Person({
p_name: 'Ratan Tata', country: 'India'
});
var details=person.clone();
//output would be a deep clone of Person Model
document.write(JSON.stringify(details));
<
/script>
<
/head>
<
body><
/body>
<
/html>
输出:
将以上代码保存在clone.html文件中,然后在新的浏览器中打开此文件。
文章图片
推荐阅读
- backbone.js模型haschanged
- backbone.js模型解析parse
- backbone.js模型urlroot
- backbone.js模型url
- backbone.js模型isvalid
- backbone.js模型validationerror
- backbone.js模型验证validate
- backbone.js模型tojson
- backbone.js模型destroy