我尝试了解Backbone。 在模型中更改属性时如何获取先前值?
<div id="sidebar">Color</div>
<script>
$(function () {
var Sidebar = Backbone.Model.extend({
promptColor: function() {
var cssColor = prompt("change property");
this.set({color: cssColor});
}
});
window.sidebar = new Sidebar;
sidebar.on('change:color', function() {
//How get previous value??
$('#sidebar').css({background: this.get('color') || 'orange'});
});
sidebar.promptColor();
});
如何知道更改前的值?谢谢...