尝试在 Ember 中渲染组件时找不到名为的助手

Geo*_*Geo 5 ember.js

我有以下路由器设置:

Router.map(function() {
  this.route("login");
  this.route("dashboard");
  this.route("projects", function() {
    this.route("show", {path: "/:project_id"});

    this.route('tasks', {path: "/:project_id/tasks" },function() {
      this.route('new', {path: "/new"});
      this.route('show', {path: "/:task_id"});
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

并且,在 中templates/projects/show.hbs,我想渲染用于创建新任务的组件(该组件由 ember 自动生成,但我在controllers/projects/tasks/new.js和处有自己的模板和控制器templates/projects/tasks/new.hbs )。我尝试了以下方法:

  {{tasks/new model=model}}
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

Assertion Failed: A helper named "tasks/new" could not be found
Run Code Online (Sandbox Code Playgroud)

解决这个问题的正确方法是什么?

Emb*_*eak 3

{{tasks/new这里task/new可以是 Component 或 Helper,但不能是模板 hbs。如果您想包含tasks/new在其中templates/projects/show.hbs,那么我鼓励您创建组件tasks/new并将其包含在您需要的地方。

您可以通过为模板 hbs 提及不同的 templateName 来尝试。使用templateName财产。内部show.js路由文件定义templateName: 'projects/tasks/new'