I am creating a leader board and need to rotate views that contain data that the team wants to see. I am using WebAPI with Durandal.
I have a collection of strings that contain the name of each of the modules. This lives in Durandals app.js (called moduleList)
define(['./system', './viewEngine', './composition', './widget', './modalDialog', './events'],
function(system, viewEngine, composition, widget, modalDialog, Events) {
var app = {
title: 'Application',
moduleList: [
"petsSoldToday",
"conversionRatioToday"
]
.
.
.
};
Events.includeIn(app);
return app;
});
What I would like to do is call router.activate([moduleName]) on a loop so that all the modules will be displayed, one by one.
I have tried creating something simple in the shell.js activate function that basically calls
setTimeout(router.activate(current), 10000);
current being the next module in the list. However, this causes a javascript error
Uncaught SyntaxError: Unexpected identifier
I don't see anything in the stack that shows why either. Honestly, I don't know what else to try.
How can this be done? Can it be done at all?
The code in your setTimeout function is executed immediately and that value is then passed to the setTimeout method (given you an error, because activate does not return a function).
You should put it inside a closure:
setTimeout(function(){
router.activate(current)
}, 10000);