0

伙计们,我正在尝试从 DateJS 对象中获取月份名称。如果我 console.log 对象,我会得到它的所有功能。但是,如果我尝试使用,例如 getMonthName/getDayName/isBefore/isAfter/etc,您会收到一条错误消息,指出该函数不存在。

任何想法?

谢谢!

更新:

这是我的代码:

App.Views.DaysTable = Backbone.View.extend({
el: '#dtable',
template: _.template( App.Templates.DaysTable ),
templateTH: _.template( App.Templates.DaysTableTH ),

initialize: function(){
    // Defino la fecha corriente
    this.fecha = Date.today();
    // Defino los eventos de la navegacion
    var that = this;
    $('#prevWeekBtn').on('click', function(){
        that.lessWeek();
    });

    $('#nextWeekBtn').on('click', function(){
        that.plusWeek();
    });

    $('#todayBtn').on('click', function(){
        that.hoy();
    });
},

hoy: function(){
    this.fecha = Date.today();
    this.render();
},

plusWeek: function(){
    this.fecha.add(7).days();
    this.render();
},

lessWeek: function(){
    this.fecha.add(-7).days();
    this.render();
},
//between date
render: function(){

    var date = this.fecha;

    this.$el.html( this.template({ month: this.fecha.getMonthName() }) );
    var a = 1;
    while(a < 8){       
        this.$('tr#days').append( this.templateTH({dayName: date.getDayName(), dayDate: date.toString('dd')}) )
        date.addDays(1);
        a++;
    }

    this.collection.each( function(bed){
        this.fecha.add(-7).days();
        bed.set('fecha', this.fecha);
        var row = new App.Views.BookingsRow({ model: bed })
        this.$('tbody#days').append( row.render().el );
    }, this);

    this.fecha.add(-7).days();
    return this;
    // Muestro los dias en cada habitacion
}
});

这是错误消息: TypeError: this.fecha.getMonthName is not a function

4

1 回答 1

1

我解决了那个问题。我不得不更改我的代码。事实证明,在最新版本的 DateJS 中,不再有 getMonthName/getDayName。现在,要打印月份名称,请使用:

Date.today().toString('MMMM');

或者一天:

Date.today().toString('dddd');

现在我遇到另一个问题,但我会打开另一个线程。

谢谢!

于 2013-03-06T21:33:54.133 回答