Backbone.js changedAttributes 模型返回自上次設置以來已更改的模型屬性的哈希值。如果沒有屬性,則為 false。
用法:
model.changedAttributes(attributes)
參數說明:
attributes:屬性定義模型的屬性。
讓我們舉個例子。
看這個例子:
<!DOCTYPE html>
<head>
<title>changedAttributes 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 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>
輸出:
將上述代碼保存在 changedattributes.html 文件中,並在新瀏覽器中打開此文件。

相關用法
- Backbone.js model.changed()用法及代碼示例
- Backbone.js model.clear()用法及代碼示例
- Backbone.js model.clone()用法及代碼示例
- Backbone.js model.cid()用法及代碼示例
- Backbone.js model.url()用法及代碼示例
- Backbone.js model.save()用法及代碼示例
- Backbone.js model.hasChanged()用法及代碼示例
- Backbone.js model.escape()用法及代碼示例
- Backbone.js model.previousAttributes()用法及代碼示例
- Backbone.js model.unset()用法及代碼示例
- Backbone.js model.idAttribute()用法及代碼示例
- Backbone.js model.toJSON()用法及代碼示例
- Backbone.js model.id()用法及代碼示例
- Backbone.js model.urlRoot()用法及代碼示例
- Backbone.js model.attributes()用法及代碼示例
- Backbone.js model.get()用法及代碼示例
- Backbone.js model.sync()用法及代碼示例
- Backbone.js model.set()用法及代碼示例
- Backbone.js model.fetch()用法及代碼示例
- Backbone.js model.isValid()用法及代碼示例
注:本文由純淨天空篩選整理自 Backbone.js model.changedAttributes()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。