EmberJS:拒绝即将到来的转型 [英] EmberJS: reject an upcoming transition

查看:340
本文介绍了EmberJS:拒绝即将到来的转型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个emberjs应用程序,用于编辑对象的表单。

此页面包含一个保存按钮,将数据保存到数据库中。

I have an emberjs app, with a form to edit an object.
This page contains a "Save" button, which persists the data into the database.

如果对象很脏,并且用户将要转换到应用程序中的其他路径,我需要警告他们,如果拒绝该确认,则取消转换。

If the object is dirty and the user is going to be transitioned to an other path in the app, I need to warn them about that, and cancel the transition if they reject the confirmation.

App.ObjectEditRoute = Ember.Route.extend
  exit: ->
    if @get('model.isDirty')
      if confirm('All your changes will be lost')
        # We just keep rolling the chain of events and do the transition
      else
        # We want to cancel the transition

似乎没有任何

推荐答案

自从路由器改装以来,这很容易使用willTransition事件。

Since the router facelift, this is pretty easy to do using the willTransition event.

App.ObjectEditRoute = Ember.Route.extend
  events:
    willTransition ->
      if @get('model.isDirty')
        if confirm('All your changes will be lost')
          transition.perform()
        else
          transition.abort()

这篇关于EmberJS:拒绝即将到来的转型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆