我是Durandal的新手,刚刚开始使用它。我开始使用示例应用程序并开始修改它,但在路由方面遇到了这个错误,我被卡住了,请帮助:
堆栈跟踪:
Uncaught TypeError:无法读取未定义的属性"then"activator.js?bust=1386627525810:141(匿名函数)activator.js?bust=1386627525810:141 jQuery.extend.Deferredjquery-1.9.1.js:1248 system.defer system.js?半身像=1386627525810:218是否可以停用Item activator.js?半身像=1386627525810:130computed.canactivateItem activator.js?半身像=1386627525810:240(匿名函数)activator.js?半身像=1386627525810:300jQuery.extend.Deferred jQuery-1.9.1.js:1248 system.defersystem.js?bust=1386627525810:218计算。激活项activator.js?胸围=1386627525810:285激活路线router.js?bust=1386627525810:257后续激活router.js?bust=1386627525810:328(匿名函数)router.js?bust=1386627525810:360(匿名函数)jquery-1.9.1.js:1192 fire jquery-1.9.1.js:1037 self.fireWithjquery-1.9.1.js:1148延迟。(匿名函数)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>
有什么想法/解释吗?任何关于如何尝试进一步调试的建议都将不胜感激!
then
通常与像Q.js这样的promise库相关联。它基本上是说异步运行一个函数,然后运行传入的函数。您遇到的错误是因为正在运行的函数没有返回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;
}
});