使用requirejs加载momentjs会导致应用程序挂起

时间:2014-05-21 13:20:25

标签: asp.net-mvc requirejs momentjs durandal-2.0

我想在我的网络应用程序中要求momentjs。我在服务器端使用ASP.NET MVC,在客户端使用Durandal。

requirejs.config({
urlArgs: "bust=" + (new Date()).getTime(),
paths: {
    'text': '../Scripts/text',
    'durandal': '../Scripts/durandal',
    'plugins': '../Scripts/durandal/plugins',
    'transitions': '../Scripts/durandal/transitions',
    'moment': '../Scripts/moment'
},
noGlobal: true

});

然后这是我的定义函数

define(['moment'], function(moment) {
    moment().format();
});

我正在Moment.js Docs直接工作 我可以看到moment.js脚本已加载但是一旦它通过define函数,应用程序就坐在那里。如果我采取定义一切正常。

有人可以帮我弄清楚我在这里做错了什么吗?

我正在添加整个main.js文件的小提琴,这可能会有所帮助。

1 个答案:

答案 0 :(得分:0)

我认为我可能误解了require.js的概念。我将我的main.js文件更改为没有返回时刻的定义,而只是添加了一个看起来像这样的新模块..

define(['moment'], function() {
return {
    dates: {
        getSimpleDate: getSimpleDate,
        getDateTime: getDateTime
    }
};

function getSimpleDate (date) {
        return moment(date).format('DD-MMM-YYYY');;
};

function getDateTime(date) {
    return moment(date).format('DD-MMM-YYYY H:mm:ss a');
}
});

这似乎很好。