gsr...@gmail.com
unread,Jul 29, 2013, 9:39:13 AM7/29/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to duran...@googlegroups.com
As part of my project, I need to retrieve the routes from an ajax call to Web API. I’m having troubles getting this working in Durandal 2. I’m sure I’m just missing something simple but I thought I’d post it here to get some help.
shell.js
define(['durandal/system', 'plugins/router'],
function (system, router) {
var applicationsData = [];
var shell = {
activate: activate,
router: router
};
return shell;
function activate() {
system.log('Lifecycle : activate : shell');
getApplications();
system.log(applicationsData);
return router.map(applicationsData).buildNavigationModel().mapUnknownRoutes('dashboards/index', 'not-found').activate();
return true;
}
function getApplications() {
// Set the ajax call options
var options = {
url: window.rootUrl + 'api/Applications',
type: 'GET',
dataType: 'json'
};
// Make the ajax call to the server
return $.ajax(options)
.then(querySucceeded)
.fail(queryFailed);
// Handle the success callback
function querySucceeded(data) {
data.forEach(function (application) {
system.log(application);
applicationsData.push(application);
});
system.log(applicationsData);
}
// Handle the fail callback
function queryFailed(jqXHR, textStatus, errorThrown) {
system.log('Error retrieving the data from the server. textStatus: ' + textStatus + ' | errorThrown: ' + errorThrown);
}
}
/*
return {
router: router,
activate: function () {
return router.map([
{ route: '', moduleId: 'dashboards/index', title: 'Dashboards', nav: true },
{ route: 'reports', moduleId: 'reports/index', title: 'Reports', nav: true }
]).buildNavigationModel()
.mapUnknownRoutes('dashboards/index', 'not-found')
.activate();
}
};
*/
});
Returned json/object from Web API call (the system.log calls in my getApplications function)
Object {route: "", moduleId: "dashboards/index", title: "Dashboards", nav: true}
Object {route: "reports", moduleId: "reports/index", title: "Reports", nav: true}
The system.log call in the activate method always shows [] (an empty array), thus the routes don’t get populated in the router.map call.
What am I missing? How can I query Web API to get my route information and populate the returned data into the router.map call?
Thanks.