lundi 2 février 2015

Getting a list of routes in Ember.js

On my main page (index.hbs), I need to display a list of links to each route which matches a given criteria, (e.g. has a certain attribute). So what I need is something like this:



// Define a route with some attribute
App.FirstRoute = Ember.Route.extend({
showOnIndex: true
});

// Get a list of visible routes in the IndexController
visibleRoutes: function() {
var routes = /* How to do this */
return routes.filter(function(route) {
route.get('showOnIndex'));
});
}.property()


The problem is how to get routes. I have found that I can get a list of route names by:



var router = this.get('target');
var names = router.router.recognizer.names;


But I can't find out how to translate them into Route objects. Presumably the Router has the information to do so, but AFAICS it is not publically exposed. Any suggestions?





Aucun commentaire:

Enregistrer un commentaire