我有以下路由器设置:
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)
解决这个问题的正确方法是什么?
{{tasks/new
这里task/new
可以是 Component 或 Helper,但不能是模板 hbs。如果您想包含tasks/new
在其中templates/projects/show.hbs
,那么我鼓励您创建组件tasks/new
并将其包含在您需要的地方。
您可以通过为模板 hbs 提及不同的 templateName 来尝试。使用templateName
财产。内部show.js
路由文件定义templateName: 'projects/tasks/new'