How to manage newly created objects without “saving” before transitioning to a new route it in emberjs?

我怕爱的太早我们不能终老 提交于 2019-12-04 20:38:06

Any code that you place in the deactivate method of your route will get executed every time you leave that route. The following code will delete the new model if the user hasn't explicitly saved it.

App.RecipesNewRoute = Ember.Route.extend({
    // ...

    deactivate: function() {
        var controller = this.controllerFor('recipes.new');
        var content = controller.get('content');
        if (content && content.get('isNew') && !content.get('isSaving'))
            content.deleteRecord();
    },

    // ...
});

As an added bonus, you now don't need to explicitly delete the record when the user presses the cancel button.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!