IndexRoute中的Controller.set

时间:2013-04-19 16:41:55

标签: ember.js

我有以下js代码:

App = Ember.Application.create({
    LOG_TRANSITIONS: true
});

App.Router.map(function() {
    this.resource('posts');
    this.resource('about');
});

App.IndexRoute = Ember.Route.extend({
     setupController: function(controller) {
         controller.set('title', "test");
     }
});

App.PostsRoute = Ember.Route.extend({
    setupController: function(controller) {
        controller.set('title', 'test');
    }
});

关注html页面:

<script type="text/x-handlebars">
    <div class="container">
        <div class="navbar">
            <div class="navbar-inner">
                <ul class="nav">
                    <li>{{#linkTo index}}Home{{/linkTo}}</li>
                    <li>{{#linkTo posts}}Posts{{/linkTo}}</li>
                    <li>{{#linkTo about}}About{{/linkTo}}</li>
                </ul>
            </div>
        </div>
        {{title}} // <--- no title here
        {{outlet}}
    </div>
</script>

<script type="text/x-handlebars" id="about">
    About template
</script>

<script type="text/x-handlebars" id="posts">
    <h1>{{title}}</h1> // <--- works here
    Recent posts
</script>

我只在帖子路线上获得了{{title}}变量。但它在索引路线上不起作用。我正在阅读手册并尝试完全按照那里提到的那样做:http://emberjs.com/guides/routing/defining-your-routes/

0 个答案:

没有答案