3

我有以下路线

App.Router.map(function(match) {
    this.route("days", { path: "/" });
    this.resource("day", { path: "/:day_id" }, function() {
        this.resource("slots", { path: "/slots" }, function() {
            this.resource("slot", { path: "/:slot_id" }, function() {
                this.route("edit", { path: "/edit" });
            });
        });
    });
});

我有以下模板

script/app/templates/application.handlebars
script/app/templates/days.handlebars
script/app/templates/day.handlebars
script/app/templates/day/index.handlebars
script/app/templates/slots.handlebars
script/app/templates/slots/index.handlebars
script/app/templates/slot.handlebars
script/app/templates/slot/index.handlebars
script/app/templates/slot/edit.handlebars
  1. 以上是否正确
  2. 如果我打算执行以下操作(不包括几天),每个车把模板中应该包含什么 html
  3. 假设我要执行以下操作(不包括天数),我需要定义哪些路线

    • 选择一天时,我想显示关联模型的列表(在这种情况下为插槽)
    • when a slot is selected I want the html from it's index page (showing an individual slot based on the slot id param being passed to the route)

更新

到目前为止,看起来标有“资源”的路由需要有一个 {{outlet}} 可用于内部资源或路由以放入一些标记。

例如 day.handlebars 模板有一个 {{outlet}} 并且在我的 day/index.handlebars 模板中我放入一个 for 循环来显示每一天。接下来在 slot.handlebars 模板中,我包含一个 {{outlet}} 并在 slot/index.handlebars 模板中添加另一个 for 循环以显示每个可用的插槽。

4

2 回答 2

3

添加到 Jakub 的答案中 - 在嵌套资源的情况下,通常(当您希望子项在父项上呈现时)xyz.handlebars应该只包含出口,并且您想成为 xyz 模板一部分的任何 html 都应该进入xyz/index .车把。那是因为无论何时你回到父资源,它都不会被重新渲染,因为 ember 假定它一直存在。但是兄弟姐妹总是会被重新渲染,在你的情况下是 slot/index 和 slot/edit

关于路线,任何必须有孩子的东西都是资源。在您的情况下 , host/#/dayshosts/#/day都被渲染到应用程序出口中

于 2013-10-04T18:00:48.713 回答
2

来了

script/app/templates/application.handlebars - {{outlet}}
script/app/templates/days.handlebars - template, but it should be a `resource` 
                                       instead of a route, which results in this
script/app/templates/days/index.handlebars - will be rendered on `/days`


script/app/templates/day.handlebars - {{outlet}} inserted into `application` outlet
script/app/templates/day/index.handlebars - inserted into `day` outlet

script/app/templates/slots.handlebars - {{outlet}} inserted into `day` outlet
// this also overwrites `day/index` template, so only one of them 
// can be displayed at once

script/app/templates/slots/index.handlebars - inserted into `slots` outlet
script/app/templates/slot.handlebars - {{outlet}} inserted into `slots` outlet
script/app/templates/slot/index.handlebars - inserted into `slot` outlet
script/app/templates/slot/edit.handlebars - inserted into `slot` outlet

您还应该定义days为资源

this.resource("days", { path: "/" });

它对其他路线没有任何影响,这条路线仍然有效

this.resource("day", { path: "/:day_id" } ...

于 2013-02-05T18:08:15.570 回答