durandal routing错误'无法读取属性'然后'未定义',这是什么意思?

时间:2013-12-09 22:33:44

标签: routing durandal

我是Durandal的新手,刚刚开始使用它。我开始使用示例应用程序并开始修改它但是遇到路由时出现此错误,我被卡住了,请帮忙:

堆栈追踪:

  

未捕获的TypeError:无法读取未定义的属性'then'   activator.js?bust = 1386627525810:141(匿名函数)   activator.js?bust = 1386627525810:141 jQuery.extend.Deferred   jquery-1.9.1.js:1248 system.defer system.js?bust = 1386627525810:218   canDeactivateItem activator.js?bust = 1386627525810:130   computed.canDeactivateItem activator.js?bust = 1386627525810:240   (匿名函数)activator.js?bust = 1386627525810:300   jQuery.extend.Deferred jquery-1.9.1.js:1248 system.defer   system.js?bust = 1386627525810:218 computed.activateItem   activator.js?bust = 1386627525810:285 activateRoute   router.js?bust = 1386627525810:257 ensureActivation   router.js?bust = 1386627525810:328(匿名函数)   router.js?bust = 1386627525810:360(匿名函数)   jquery-1.9.1.js:1192 fire jquery-1.9.1.js:1037 self.fireWith   jquery-1.9.1.js:1148 deferred。(匿名函数)   jquery-1.9.1.js:1237(匿名函数)

我的Shell.js看起来像:

define(['plugins/router', 'durandal/app'], function (router, app) {
    return {
        router: router,
        search: function() {
            //It's really easy to show a message box.
            //You can add custom options too. Also, it returns a promise for the user's response.
            app.showMessage('Search not yet implemented...');
        },
        activate: function () {
            router.map([
                  { route: '', title: 'Budget', moduleId: 'viewmodels/budget' },
                  { route: 'Back', title: 'Back to User Screens', moduleId: 'viewmodels/back', nav: true },
                  { route: 'Budget', title: 'Budget', moduleId: 'viewmodels/budget', nav: true },


            ]).buildNavigationModel();

            return router.activate();
        }
    };
});

Back.js和back.html基本上都是空的,所有我希望这个页面要做的是重定向回我的旧应用程序,我想要durandal作为我正在构建的应用程序的新部分,我在想慢慢将一切都迁移到durandal:

define(['plugins/http', 'durandal/app', 'knockout'], function (http, app, ko) {
        //Note: This module exports an object.
        //That means that every module that "requires" it will get the same object instance.
        //If you wish to be able to create multiple instances, instead export a function.
        //See the "welcome" module for an example of function export.

    return {

        };
    });

back.html:

<section>
    <script language="javascript">
        window.location.replace('/Project');
    </script>
</section>

任何想法/解释?关于如何进一步调试的任何建议都表示赞赏!

1 个答案:

答案 0 :(得分:1)

then通常与Q.js等承诺库相关联。它基本上是说异步运行一个函数然后运行传入的函数。你遇到的错误将是因为正在运行的函数没有返回一个promise或者返回别的东西或者什么也没有。

查看您提供的Back.js文件,它需要至少为durandal设置一个激活函数才能正确加载页面,我认为这将是您的主要问题。

define(['plugins/http', 'durandal/app', 'knockout'], function (http, app, ko) {
    //Note: This module exports an object.
    //That means that every module that "requires" it will get the same object instance.
    //If you wish to be able to create multiple instances, instead export a function.
    //See the "welcome" module for an example of function export.

    var vm = {
        activate: activate
    };

    return vm;

    function activate() {
        return true;
    }
});