I am using a json file pulled from the server to configure my website, and to tell each page what it's title is. The json file looks like this:
[{"route": "student", "title": "Student Info Page"}, {"route": "payments", "title": "Payments and Pricing"}, {"route": "policy", "title": "Mine"}, {"route": "biography", "title": "About Me"}]
which is used to create a navigation bar with this code:
App.MenuController = Ember.ArrayController.create();
$.get('config.json', function(data) {
App.MenuController.set('content', data);
});
which is then used in the template:
{{#each App.MenuController}}
{{#varLink route this}}{{title}}{{/varLink}}
{{/each}}
All of this works great so far.
So here's my question: I want the route mapping done with App.Router.map
to be done programatically, using this json object to determine which routes should exist.
How on earth should I do this? I've hunted around the documentation, and then tried this:
$.get('config.json', function(data) {
App.MenuController.set('content', data);
for (var i = 0; i < data.length; i++) {
App.Router.map(function(){
var r = data[i].route;
console.log(r);
this.route(r);
});
}
});
which gives the following console readout:
student app.js:9
payments app.js:9
policy app.js:9
biography app.js:9
Assertion failed: The attempt to linkTo route 'student' failed. The router did not find 'student' in its possible routes: 'index' ember.js:361
Uncaught Error: There is no route named student.index ember.js:23900