这就是我的示例项目 (8,3 MB) Visual Studio 2012 解决方案:
我的问题:
模块step2及其 compositionComplete 事件未被调用!模块step1是并且相同的事件工作正常!
这样您就可以重现问题:
1.) 启动应用程序
2.) 点击“浏览学年”按钮
3.) 单击“创建”按钮(打开 SchoolyearWizard)
4.) 向导 step1 是可见的,它的 compositionComplete 事件被调用
5.) 单击“下一步”按钮
6.) 向导 step2 是可见的,并且它的 compositionComplete 事件没有被调用
我在这里只发布重要的东西,这些是 5 个模块。
- SchoolyearDialog 模块由 SchoolyearBrowser 和 SchoolyearWizard 模块组成。两个模块都使用“compose:activeScreen”绑定进行切换。
- 当加载 SchoolyearWizard 并且用户单击下一步按钮以加载 step2 时,这里是问题,请参见上面的数字 6。)。
学年对话
define(['durandal/app','plugins/dialog', 'knockout', 'services/dataservice', 'plugins/router', 'moment'], function (app, dialog, ko, dataservice, router, moment) {
var SchoolyearDialog = function () {
var self = this;
self.activeScreen = ko.observable('viewmodels/SchoolyearBrowser'); // set the schoolyear browser as default module
app.on('activateStep1').then(function (obj) {
self.activeScreen(obj.moduleId);
});
app.on('activateStep2').then(function (obj) {
self.activeScreen(obj.moduleId);
});
app.on('dialog:close').then(function (options) {
dialog.close(self, options );
});
self.closeDialog = function () {
dialog.close(self, { isSuccess: false });
}
}
SchoolyearDialog.show = function () {
return dialog.show(new SchoolyearDialog());
};
return SchoolyearDialog;
});
学年浏览器
define(['durandal/app', 'plugins/dialog', 'knockout', 'services/dataservice', 'plugins/router', 'moment'],
function (app, dialog, ko, dataservice, router, moment) {
var SchoolyearBrowser = function () {
var self = this;
self.create = function () {
app.trigger('activateStep1', {
moduleId: 'viewmodels/SchoolyearWizard',
viewMode: 'create'
});
}
self.open = function () {
// do not open the wizard
}
self.compositionComplete = function (view) {
debugger;
}
};
return SchoolyearBrowser;
});
学年向导
define(['durandal/activator', 'viewmodels/step1', 'viewmodels/step2', 'knockout', 'plugins/dialog','durandal/app'], function (activator, Step1, Step2, ko, dialog, app) {
var steps = [new Step1(), new Step2()];
var step = ko.observable(0); // Start with first step
var activeStep = activator.create();
var stepsLength = steps.length;
var hasPrevious = ko.computed(function () {
return step() > 0;
});
var caption = ko.computed(function () {
if (step() === stepsLength - 1) {
return 'save';
}
else if (step() < stepsLength) {
return 'next';
}
});
activeStep(steps[step()]);
var hasNext = ko.computed(function () {
if ((step() === stepsLength - 1) && activeStep().isValid()) {
// save
return true;
} else if ((step() < stepsLength - 1) && activeStep().isValid()) {
return true;
}
});
return {
showCodeUrl: true,
steps: steps,
step: step,
activeStep: activeStep,
next: next,
caption: caption,
previous: previous,
hasPrevious: hasPrevious,
hasNext: hasNext
};
function isLastStep() {
return step() === stepsLength - 1;
}
function next() {
if (isLastStep()) {
// Corrects the button caption when the user re-visits the wizard
step(step() - 1);
// Resets the wizard init page to the first step when the user re-visits the wizard
activeStep(steps[0]);
debugger;
// save;
}
else if (step() < stepsLength) {
step(step() + 1);
activeStep(steps[step()]);
debugger;
//app.trigger('activateStep2', {
// moduleId: 'viewmodels/step2'
//});
}
}
function previous() {
if (step() > 0) {
step(step() - 1);
activeStep(steps[step()]);
}
}
});
步骤1
define(function () {
return function () {
var self = this;
self.isValid = function () {
return true;
}
self.name = 'step1';
self.compositionComplete = function (view) {
debugger;
}
};
});
第2步
define(function () {
return function () {
this.isValid = function () {
return true;
}
this.name = 'step2';
self.compositionComplete = function (view) {
// I never get here WHY ???
}
};
});