我有一个带有区域的互联网应用程序mvc4,对于我的组织,每个区域代表一个SPA,通过"管理NuGet包",我安装了"Durandal 1.2.0","Durandal Transitions 1.2.0"和"Durandal Router 1.2.0".我组织了文件夹并退出Durandal文件夹"App"中的"views"和"viewmodels",并将新视图放在mvc4区域的文件夹"VIews"中,例如:
领域 - > NewArea - >查看 - > ControllerFolder - >视图 - > shell.html
然后我将'"viewmodels"放在"Script"文件夹中,例如:
脚本 - > NewArea - > ControllerFolder - >的ViewModels - > shell.js
脚本 - > NewArea - > ControllerFolder - > main.js
然后我改变了durandal JS的路径,例如在main.js中:
define(['../../../App/durandal/app',
'../../../App/durandal/viewLocator',
'../../../App/durandal/system',
'../../../App/durandal/plugins/router',
'../../../App/services/logger'],
Run Code Online (Sandbox Code Playgroud)
我在下一行改变了main.js:
viewLocator.useConvention('viewmodels', '../Areas/NewArea/Views/ControllerFolder/views');
Run Code Online (Sandbox Code Playgroud)
但是文件夹的配置失败,因为下一行在其定义中调用了模块"viewLocator"的不同时间,并使用默认值重写"useConvention"的配置:
app.setRoot('viewmodels/shell', 'entrance');
Run Code Online (Sandbox Code Playgroud)
仅当文件夹"views"和"viewmodels"不在"Durandal"的"App"文件夹下时才会发生这种情况.
请帮助我,如何在同一个项目中拥有各种SPA?
我需要为数组的所有项动态执行函数,但是Array.forEach按顺序执行,我需要在异步中执行.
items.forEach(function(item) {
doSomething(item);
});
Run Code Online (Sandbox Code Playgroud)
我试试这个:
var promises = [];
items.forEach(function(item) {
var promise = function() {
return Q.fcall(function() {
doSomething(item);
});
};
promises.push(promise());
});
Q.all(promises).then(function () {
otherFunction(datacontext.mainList); //use datacontext.mainList filled.
});
Run Code Online (Sandbox Code Playgroud)
但执行总是按顺序执行,我需要并行执行.
该doSomething(item)方法:
function doSomething(item) {
var children = getChildren(item); //get data from local with manager.executeQueryLocally
var total = getTotal(children); //simple calculations
datacontext.mainList.push({
name: item.firstName() + ' ' + item.lastName(),
total: total
});
}
Run Code Online (Sandbox Code Playgroud)
请帮我.