【问题标题】:Ember can't find my template when using the renderTemplate hook使用 renderTemplate 挂钩时,Ember 找不到我的模板
【发布时间】:2018-09-12 06:21:25
【问题描述】:

我不明白为什么 Ember 无法找到并呈现在我的 renderTemplate 挂钩覆盖中指定的模板。根据router.js,我有以下路由配置:

  this.route('posts', function() {
   this.route('history', function() {
    this.route('new', { path: '/new/:id'});
   });
  });

我也在利用我的历史index 路线。因此,我的history.hbs 只是一个出口,我为这条路线制作的所有模板实际上都存放在index.hbs 中。这样,我可以在自己的页面上呈现我的new.hbs 模板。

在new.hbs 中,除了一些其他内容之外,我还想渲染一个出口。为了解决这个问题,我尝试覆盖routes/new.js 中的renderTemplate 钩子,如下所示:

  renderTemplate() {
   this.render('posts/history/test', {
    into: 'new',
    outlet: 'test',
   });
  }

我在templates/posts/history:test.hbs` 下创建了新模板。我的模板文件夹的文件结构如下所示:

templates > posts > history > new.hbs, test.hbs

最后,在new.hbs,我为这个新模板添加了出口:

{{outlet 'test'}}

当我导航到我的 new 路线时,我收到以下错误: Assertion Failed: You attempted to render into ’new' but it was not found。任何人都知道我该如何克服这个问题?

【问题讨论】:

  • 你可以尝试`进入:'posts/history/new'`
  • 很遗憾不起作用
  • 尝试使用 • 而不是 /
  • 还是什么都没有:/

标签: ember.js


【解决方案1】:

我相信你只能渲染成祖先路线。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-23
  • 1970-01-01
  • 1970-01-01
  • 2015-12-14
  • 1970-01-01
  • 2017-11-13
  • 1970-01-01
相关资源
最近更新 更多