2

我可能读错了文档。有人可以查看我的要点并告诉我为什么invoices/index模板没有呈现吗?

当我阅读ember.js 文档时,它声明它应该呈现

posts
 ↳posts/index

invoices/index在我的情况下)。然而,invoices模板呈现。

车把:

<script type="text/x-handlebars" data-template-name="application">
    <h1>Ember Committers</h1>
    <nav>
        {{#linkTo "index"}}Index{{/linkTo}}
        {{#linkTo "about"}}About{{/linkTo}}
        {{#linkTo "invoices"}}Invoices{{/linkTo}}
    </nav>
    {{ outlet }}
</script>

<script type="text/x-handlebars" data-template-name="invoices">
    <h1>Invoices</h1>
</script>

<script type="text/x-handlebars" data-template-name="invoices/index">
    <ul>
        {{#each invoice in invoices }}
        <li>{{#linkTo "show" invoice.id}}{{ invoice.id }}{{/linkTo }}</li>
        {{/each }}
    </ul>
</script>

<script type="text/x-handlebars" data-template-name="invoices/show">
    <p>Invoice - {{ name }}</p>
</script>

<script type="text/x-handlebars" data-template-name="phone">
    <p>Contributor - {{ title }}</p>
</script>

<script type="text/x-handlebars" data-template-name="about">
    <p>About {{ title }}</p>
</script>

<script type="text/x-handlebars" data-template-name="index">
    <p>Index</p>
</script>

JavaScript:

<script type="text/javascript" defer>
    var App = Ember.Application.create({
        LOG_TRANSITIONS: true
    });
    App.ApplicationView = Ember.View.extend({
        templateName: 'application'
    });

    App.Router.map(function () {
        this.route("about");
        this.resource("invoices", { path: "/invoices" }, function () {
            this.resource("show", { path: "/:id" });
        });
    });

    var invoices = [
        {id: 1},
        {id: 2}
    ];

    App.AboutRoute = Ember.Route.extend({
        setupController: function (controller) {
            // Set the IndexController's `title`
            controller.set('title', "My App");
        }
    });

    App.InvoicesIndexController = Ember.ArrayController.extend({
        invoices: invoices
    });

</script>
4

1 回答 1

4

您需要在模板中包含一个{{outlet}}标签。invoices由于indexshow是 的嵌套资源invoices,因此它们的模板会在您在模板中指定的插座内呈现invoices

查看 Ember.js 指南的嵌套资源部分。

于 2013-03-05T02:36:08.593 回答