Backbone.js PreviousAttributes模型返回上一次更改事件之前模型的先前属性。它用于获取模型版本之间的差异,或在发生错误后恢复先前的属性。
句法:
model.previousAttributes()
让我们举个例子。
请参阅以下示例:
<!DOCTYPE html>
<head>
<title>PreviousAttributes Example</title>
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
var model = new Backbone.Model({
jersey:10, player:'Dhoni', country:'India'
});
model.set('jersey', '99');
document.write("All the attributes returned by the previousAttributes() method are: ");
document.write("<br>");
document.write(JSON.stringify(model.previousAttributes()));
</script>
</body>
</html>
输出:
将以上代码保存在previousattributes.html文件中,然后在新的浏览器中打开此文件。
评论前必须登录!
注册