Ember.js 余烬-在控制器或路由中设置主页标题?

Ember.js 余烬-在控制器或路由中设置主页标题?,ember.js,Ember.js,最佳做法是什么 这是我的HTML: <script type="text/x-handlebars"> <div id="top-panel"> <h1>{{title}}</h1> </div> <div id="wrapper"> <div id="content"> {{outlet}} </div>

最佳做法是什么

这是我的HTML:

<script type="text/x-handlebars">
    <div id="top-panel">
        <h1>{{title}}</h1>
    </div>
    <div id="wrapper">
        <div id="content">
            {{outlet}}
        </div>
    </div>
</script>
第二:

App.ApplicationController = Ember.ObjectController.extend({
    title: "Hello World"
});

哪一种方法是推荐的?

如果它只是一个永远不会改变的静态对象,我会将它放在第二个,或者只是放在车把模板中

另外

  • 由于您没有在应用程序控制器上设置对象,因此它实际上不需要扩展ObjectController,您只需扩展控制器即可

    Ember.ObjectController is part of Ember's Controller layer. It is intended to 
    wrap a single object, proxying unhandled attempts to get and set to the 
    underlying content object, and to forward unhandled action attempts to its target.
    
  • 将来,如果要覆盖setupController,通常建议将其称为超级(控制器、模型),如:

  • setupController的默认实现是在控制器上设置内容,因此从技术上讲,不调用super没有什么区别

    对于动态标题,我会将其设置为计算属性:

     App.ApplicationController = Ember.ObjectController.extend({
         title: function(){
            var currentdate = new Date(),
                title = "Awesome Title: " + currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/" 
                + currentdate.getFullYear() + " @ "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":" 
                + currentdate.getSeconds();
    
              return title;
         }.property()
     });
    

    如果它只是一个静态的东西,永远不会改变,我会把它放在第二个,或只是在把手模板

    另外

  • 由于您没有在应用程序控制器上设置对象,因此它实际上不需要扩展ObjectController,您只需扩展控制器即可

    Ember.ObjectController is part of Ember's Controller layer. It is intended to 
    wrap a single object, proxying unhandled attempts to get and set to the 
    underlying content object, and to forward unhandled action attempts to its target.
    
  • 将来,如果要覆盖setupController,通常建议将其称为超级(控制器、模型),如:

  • setupController的默认实现是在控制器上设置内容,因此从技术上讲,不调用super没有什么区别

    对于动态标题,我会将其设置为计算属性:

     App.ApplicationController = Ember.ObjectController.extend({
         title: function(){
            var currentdate = new Date(),
                title = "Awesome Title: " + currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/" 
                + currentdate.getFullYear() + " @ "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":" 
                + currentdate.getSeconds();
    
              return title;
         }.property()
     });
    

    它将是动态的——类似于“2013年10月18日的报告”——因此标题将以日期为基础。在这种情况下,你的答案会改变吗?我会使用一个计算属性,见上文。它将是动态的——类似于“2013年10月18日的报告”——因此标题将基于日期。在这种情况下,你的答案会改变吗?我会使用计算属性,见上文。