2

当您从 index.html#/admin/authors/1/edit 转换到 index.html#/admin/authors/2/edit 时,不会调用路由上的 deactivate 。

当您从 index.html#/admin/authors/1/edit 转换到 index.html#/admin/authors/new 时,调用deactivate 路由。

我希望在这两种情况下都调用 deactivate ?

在路由级别是否有另一种方法来检测您从 ../1/edit 切换到 ../2/edit ?

我需要在主详细信息视图中使用它(主是所有作者的列表,详细信息是每个作者属性的文本字段形式)。如果用户在列表中选择了另一个作者并且之前的作者被修改而没有保存,我需要回滚事务或询问用户“你要保存更改吗?”。

4

1 回答 1

6

在这种情况下不调用 Deactivate,因为编辑路径仍然处于活动状态。要检测从 ../1/edit 到 ../2/edit 的切换,请使用路由的willTransition事件。例如:

App.FormRoute = Ember.Route.extend({
  actions: {
    willTransition: function(transition) {
      if(!this.controller.get('canNavigate')) {
        alert('non-empty form!');
        transition.abort();
      }
    }
  }
});

有关更多示例,请参阅此要点:https ://gist.github.com/machty/5647589

于 2013-08-08T20:02:46.733 回答