我是杜兰达尔的新手。我只是想知道是否有一种方法可以通过查询字符串或任何其他方式将变量传递给根视图模型(即外壳)?
所以 main.js 看起来像下面这样
define(['durandal/app'], function (app) {
app.configurePlugins({
router: true
});
app.start().then(function () {
app.setRoot('shell');
});
});
你能做一些类似于下面在 shell.js 文件中写的东西吗?我试过了,但它不起作用
function activate(variableIwantToPass) {
doSomething(variableIwantToPass);
configureRoutes(variableIwantToPass);
return router.activate();
}
function configureRoutes(variableIwantToPass) {
var specialRoute = 'bar';
if(variableIwantToPass == 'foo') {
specialRoute = foo;
}
var routes = [
{
route: '',
moduleId: 'home'
},
{
route: 'doThings/:specialRoute/',
moduleId: 'orchestrator'
}
];
router.makeRelative({ moduleId: 'viewModels'}).map(routes);
}
我无法调用服务来获取 shell 中的数据,因为我想要的信息/变量作为查询字符串参数传递到通向 spa 的页面中。
那么,是否可以将某些东西传递到外壳中,或者是否有任何其他替代方法可以实现我想要的。就像创建一个 cookie 来存储这个变量并通过 shell.js 中的 javascript 读取它一样?