backbone.js模型previousattributes

Backbone.js PreviousAttributes模型返回上一次更改事件之前模型的先前属性。它用于获取模型版本之间的差异,或在发生错误后恢复先前的属性。
句法:

model.previousAttributes()

让我们举个例子。
请参阅以下示例:
< !DOCTYPE html> < head> < title>PreviousAttributes Example< /title> < script src="http://img.readke.com/220416/04052TO6-0.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/04052S625-1.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/04052R053-2.jpg" 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>

输出:
【backbone.js模型previousattributes】将以上代码保存在previousattributes.html文件中,然后在新的浏览器中打开此文件。
backbone.js模型previousattributes

文章图片

    推荐阅读