Knockout.js 约翰·帕帕';这是热毛巾。手错误未定义…为什么?
我使用John Papa的热毛巾模板。我有这样一个viewmodel:Knockout.js 约翰·帕帕';这是热毛巾。手错误未定义…为什么?,knockout.js,error-handling,breeze,durandal,hottowel,Knockout.js,Error Handling,Breeze,Durandal,Hottowel,我使用John Papa的热毛巾模板。我有这样一个viewmodel: define(['durandal/app', 'services/appsecurity', 'services/unitofwork', 'services/errorhandler', 'services/logger', 'services/utils'], function (app, appsecurity, unitofwork, errorhandler, logger, utils) { ... ...
define(['durandal/app', 'services/appsecurity', 'services/unitofwork', 'services/errorhandler', 'services/logger', 'services/utils'],
function (app, appsecurity, unitofwork, errorhandler, logger, utils) {
...
...
unitofwork.commit()
.then(function () {
logger.logSuccess("success!", null, null, true);
})
.fail(function () {
debugger;
this.handleError //UNDEFINED!!!
});
如果我在提交过程中出错,我想我应该得到一条toast消息或一些关于该错误的通知。
我调试了代码,并意识到在fail函数中“this”是窗口对象,但它没有handleError函数
这个项目模板应该如何处理错误,我错过了什么?因为您没有显示一个。 试试这个
unitofwork.commit()
.then(function () {
logger.logSuccess("success!", null, null, true);
})
.fail(function () {
var message = 'Failed Commit !!';
logger.logError(message, error);// this will display a toast for error occured with respective moduleID name.
});
这在javascript中表示上下文,而不是对象。我认为在你的代码中,这个=窗口。是吗?我认为errorhandler服务应该以某种方式注册到窗口,并且应该定义window.handleError。但是怎么做呢?我建议你读一下:。简而言之,有两种方法:将其捕获到变量var self=this;(例如google)或使用Bind()方法。请向我们展示完整的文件以及
handleError
函数的定义位置