加载路径时出错:ReferenceError:未定义CalendarData

时间:2014-03-26 20:12:54

标签: javascript ember.js

我尝试使用函数来定义模型属性,但我在路径中遇到错误。我正在创建一个日历,以便在按月份名称排序的日期选择器中使用。是我的控制器,我的模型还是别的什么?

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 CalendarData;
    },
    serializer: function(model){
        return {month: model.get('month')};
    }
});

// calendar controller


// calendar data
App.CalendarData = Ember.Object.extend({
    today: function(){
        var Today = new Date();
        return Today;
    },

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

    month: function(){
        // 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(){
        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(){
        var Year = Today.getYear();
        return Year;
    }

});

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

1 个答案:

答案 0 :(得分:0)

好像你正在返回CalendarData,好像它是一个全局变量或范围变量,但它应该是App上下文的一部分。你试过返回App.CalendarData吗?

P.S。我想将此添加为小评论,但我没有所需的50个代表: - (