在子路由中调用一个动作

Calling an action in a child route

我有很深的嵌套路由:

App.Router.map(function() {
  this.resource('user', function() {
    this.resource('authors', function() {
      this.resource('books', function() {
        this.resource('chapters', function() {
          this.resource('chapter', {path: '/:chapter_id'});
        });
      });
    });
  });
  this.resource('home');
  this.resource('blog');
});

我在路线上遇到以下错误:

路线:/user/authors/books/chapters

错误:Error while processing route: chapters.index Cannot read property 'get' of undefined TypeError: Cannot read property 'get' of undefined

这个错误的原因是路由Books的模型为空

我想有这样的逻辑:如果各种路线的模型之一是空的,那么创建一个Ember-数据记录并将这个新记录提取到有问题的模型中。

问题: 我在 Books 路线中有一个 createBook 动作。是否可以从父 Authors 路由调用此操作,以便当 Ember 运行 Books 路由的模型时,该模型找到新创建的 Books 记录?我的方法错了吗?我应该使用其他逻辑吗?

谢谢

我决定将子路由中的 createBook 操作升级到父路由。代码有点乱(createBook 操作不在 Book 路由下)但是这样我可以从 Authors 路由调用操作。

我很乐意欢迎更有效的解决方案。