我在 yui3 中使用模型,虽然有像 Reset() 和 undo() 这样的函数,但它们并不能完全实现我正在寻找的功能。
我在不同时间设置值,但可能想撤消上次保存之前的所有内容...此时有办法这样做吗?
最佳答案
在 3.5.0pr2 中(pr2 目前已在 Yahoo! CDN 上;3.5.0 GA 将于 3 月中旬发布),您可以尝试如下操作:
var MyModelClass = Y.Base.create('mine', Y.Model, [], {
initializer: function () {
this._saveState();
this.after('save', this._saveState);
},
_saveState: function (e) {
this._lastState = this.toJSON();
},
restoreLastSaved: function () {
this.setAttrs(this._lastState);
}
});
关于javascript - 在YUI3中,有没有办法将 "reset"模型转换为以前保存的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9417842/