Ember.js模板渲染

时间:2013-03-05 01:25:20

标签: ember.js

我可能会错误地阅读文档。有人可以check out my gist并告诉我为什么invoices/index模板没有渲染吗?

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

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>

1 个答案:

答案 0 :(得分:4)

您需要在{{outlet}}模板中加入invoices标记。由于indexshowinvoices的嵌套资源,因此其模板会在您在invoices模板中指定的插座内呈现。

查看Ember.js指南的nested resources部分。