Ember.js 余烬-在控制器或路由中设置主页标题?
最佳做法是什么 这是我的HTML: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>
<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"
});
哪一种方法是推荐的?如果它只是一个永远不会改变的静态对象,我会将它放在第二个,或者只是放在车把模板中 另外
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.
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()
});
如果它只是一个静态的东西,永远不会改变,我会把它放在第二个,或只是在把手模板 另外
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.
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日的报告”——因此标题将基于日期。在这种情况下,你的答案会改变吗?我会使用计算属性,见上文。