【发布时间】:2015-02-02 08:55:08
【问题描述】:
在我的主页 (index.hbs) 上,我需要显示与给定条件匹配的每个路由的链接列表(例如,具有特定属性)。所以我需要的是这样的:
// 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()
问题是如何获得routes。我发现我可以通过以下方式获取路线名称列表:
var router = this.get('target');
var names = router.router.recognizer.names;
但我不知道如何将它们翻译成Route 对象。大概Router 有这样做的信息,但 AFAICS 它没有公开。有什么建议么?
【问题讨论】:
-
你试过 emberjs 的 firefox 或 chrome tab-plugin 吗?它被宣传它可以显示路线? github.com/emberjs/ember-inspector
-
是的,我正在使用它,但它应该有什么帮助?
标签: javascript ember.js