我试图理解 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();
});
我怎么知道更改前的值?谢谢...