backbone.js模型changedattributes

本文概述

  • 参数说明
Backbone.jschangedAttributes模型返回自上次设置以来已更改的模型属性的哈希值。如果没有属性,它将变为false。
句法:
model.changedAttributes(attributes)

参数说明属性:属性定义模型的属性。
让我们举个例子。
请参阅以下示例:
< !DOCTYPE html> < head> < title>changedAttributes Example< /title> < script src="http://img.readke.com/220416/0404555A5-0.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/0404553344-1.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/04045541P-2.jpg" type="text/javascript">< /script> < /head> < body> < script type="text/javascript"> var values = new Backbone.Model({ name1: 'Amar', name2: 'Akbar', name3: 'Anthony' }); values.on('change', function() { document.write("The changed attributes are: "); document.write(JSON.stringify(values.changedAttributes())); }); values.set({ name1: 'Peter', name2: 'Mark' }); < /script> < /body> < /html>

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

文章图片

    推荐阅读