在YUI3中,有没有办法“重置”模型到以前保存的值?

发布于 2025-01-08 18:05:29 字数 117 浏览 6 评论 0原文

我在 yui3 中使用模型,虽然有像 Reset() 和 undo() 这样的函数,但它们并不能完全实现我正在寻找的功能。

我在不同时间设置值,但可能想撤消上次保存之前的所有内容...此时有办法这样做吗?

I'm using models in yui3, and although there are functions like reset() and undo(), they don't quite accomplish what I'm looking for.

I set values at different times, but may want to just undo everything to the point of the last save... is there a way to do so at this time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独患者 2025-01-15 18:05:29

在 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);
    }
});

In 3.5.0pr2 (pr2 is currently on the Yahoo! CDN; 3.5.0 GA will be released in mid-March), you can try something like this:

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);
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文