Gilgamesh415 Gilgamesh415 - 1 year ago 71
Javascript Question

Date function not working as property

I'm trying to use date functions to declare a property in Ember, but it's not displaying. No errors but no data either. I run today = new date(); & getFullYear(today); in the console but it comes back as "undefinded". I can't get these functions to model my data. What's up?

<script type="text/x-handlebars" data-template-name="application">
<div id="navbar">
<li>{{#link-to "calendar"}}Calendar{{/link-to}}</li>
<li>{{#link-to "about"}}About{{/link-to}}</li>
<div id="content"> {{outlet}} </div>
<footer id='container'>Footer information here!</footer>

<script type="text/x-handlebars" data-template-name="about">
<p>My calendar Date picker!</>
<script type="text/x-handlebars" data-template-name="calendar">
<h1>Calendar Page</h1>



var App = Ember.Application.create({
}); {

App.IndexRoute = Ember.Route.extend({
redirect: function(){

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;

date: function(today){
var Date = Today.getDate();
return Date;

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];

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];

year: function(Today){
var Year = Today.getFullYear();
return Year;


Answer Source

I'm not sure where you got the example of how to do a computed property, but you might want to check out the guides on computed properties.

today: function(){
    var today = new Date();
    return today;

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