创建了一个导航栏模板项目,并尝试在状态之间传递参数
self.moduleConfig = ko.observable({'view': [], 'viewModel': null});
self.modelParams = ko.observable({});
self.loadModule = function () {
ko.computed(function () {
var name = self.router.moduleConfig.name();
var viewPath = 'views/' + name + '.html';
var modelPath = 'viewModels/' + name;
var masterPromise = Promise.all([
moduleUtils.createView({'viewPath': viewPath}),
moduleUtils.createViewModel({'viewModelPath': modelPath})
]);
masterPromise.then(
function (values) {
var viewModel = null;
if (values[2])
viewModel = values[1];
else
viewModel = new values[1](self.modelParams);
// self.moduleConfig({'view': values[0], 'viewModel': values[1]});
self.moduleConfig({'view': values[0], 'viewModel': viewModel});
}
);
});
};
答案 0 :(得分:0)
我已经使用了这段代码
self.loadStepModule = function () {
ko.computed(function () {
self.slotBody({'view': [], 'viewModel': null});
var myview = modviewPath + currentStep.viewName + '.html';
var mymodel = modmodelPath + currentStep.modelName;
var masterPromise = Promise.all([
moduleUtils.createView({'viewPath': myview}),
moduleUtils.createViewModel({'viewModelPath': mymodel})
]);
masterPromise.then(
function (values) {
var vm = new values[1](currentStep.dataparams);
self.slotBtns(self.currentButtonConfig());
self.slotBody({
'view': values[0],
'viewModel': vm
});
}
);
});
};