Gilgamesh415
Gilgamesh415

Reputation: 43

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?

<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()

});

http://emberjs.jsbin.com/faruk/1/

Upvotes: 0

Views: 65

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

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;
}.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

http://emberjs.jsbin.com/kogekoxo/1/edit

Upvotes: 1

Related Questions