我正在尝试使用日期函数在Ember中声明属性,但它没有显示。没有错误但没有数据。我今天跑=新约会(); &安培;和getFullYear(今天);在控制台中,但它回来时“未完成”。我无法使用这些函数来建模我的数据。怎么了?
<body>
<script type="text/x-handlebars" data-template-name="application">
<div id="navbar">
<ul>
<li>{{#link-to "calendar"}}Calendar{{/link-to}}</li>
<li>{{#link-to "about"}}About{{/link-to}}</li>
</ul>
</div>
<div id="content"> {{outlet}} </div>
<footer id='container'>Footer information here!</footer>
</script>
<script type="text/x-handlebars" data-template-name="about">
<h1>About</h1>
<p>My calendar Date picker!</>
</script>
<script type="text/x-handlebars" data-template-name="calendar">
<h1>Calendar Page</h1>
<button>Next</button>
<button>Today</button>
<button>Back</button>
<hr>
{{today}}
<hr>
</script>
</body>
var App = Ember.Application.create({
LOG_TRANSITIONS: true
});
App.Router.map(function() {
this.resource('calendar');
this.resource('about');
});
App.IndexRoute = Ember.Route.extend({
redirect: function(){
this.transitionTo('calendar');
}
});
App.CalendarRoute = Ember.Route.extend({
model: function(){
return App.CalendarData;
},
serializer: function(model){
return {month: model.get('Today')};
}
});
// calendar controller
// calendar data
App.CalendarData = Ember.Object.extend({
today: function(){
var Today = new Date();
return Today;
}.property(),
date: function(today){
var Date = Today.getDate();
return Date;
}.property(),
month: function(Today){
// this array gives month names
var MonthA = new Array();
MonthA[0] = "January";
MonthA[1] = "February";
MonthA[2] = "March";
MonthA[3] = "April";
MonthA[4] = "May";
MonthA[5] = "June";
MonthA[6] = "July";
MonthA[7] = "August";
MonthA[8] = "September";
MonthA[9] = "October";
MonthA[10] = "November";
MonthA[11] = "December";
var Month = Today.getMonth();
return MonthA[Month];
}.property('month'),
dow: function(Today){
var Weekday = new Array();
Weekday[0] = "Sunday";
Weekday[1] = "Monday";
Weekday[2] = "Tuesday";
Weekday[3] = "Wednesday";
Weekday[4] = "Thursday";
Weekday[5] = "Friday";
Weekday[6] = "Saturday";
var dow = Today.getDay();
return Weekday[dow];
}.property(),
year: function(Today){
var Year = Today.getFullYear();
return Year;
}.property()
});
答案 0 :(得分:1)
我不知道你在哪里得到了如何计算属性的例子,但是你可能想查看有关计算属性的指南。
today: function(){
var today = new Date();
return today;
}.property(),
date: function(){
var date = this.get('today').getDate(); // grab the computed property `today`
return date;
}.property('today'), // this says, when today computed property changes, you should mark this property as dirty