mercredi 9 décembre 2015

Changing controller property in action doesn't change the view

I am a newbie in ember, and i've got a problem. The point is i need to create an application where almost every page depends on selected month and year, so i decided to put that property in application controller and render to application template. Right now i have:

application controller:

    App.ApplicationController = Ember.Controller.extend({
    date: new Date(),
    current_date: function() {
        var d = this.get('date');
        var date = '01';
        var month = d.getMonth() + 1;
        var year = d.getFullYear();

        return {
            date: date,
            month: month,
            year: year
        };
    }.property('date'),

    actions: {
        previousMonth: function() {
            var date = this.get('date');
            date.setMonth(date.getMonth() - 1);
            this.set('date', date);
            console.log(this.get('date'));
        },
        nextMonth: function() {
            var date = this.get('date');
            date.setMonth(date.getMonth() + 1);
            this.set('date', date);
            console.log(this.get('date'));
        }
    }
});

application view:

 App.ApplicationView = Ember.View.extend({
    date: function() {
        var raw_date = this.get('controller.current_date');
        return raw_date.month + " " + raw_date.year;
    }.property('controller.current_date')
});

and application.js.emblem

.date_selector
    h2#month
        a click="previousMonth" href="#" prev
        current_date
        a click="nextMonth" href="#" next
outlet

Default render is ok. But when i click next or previous month nothing changes, but console shows that the value has actually changed. Do i miss something?




Aucun commentaire:

Enregistrer un commentaire