gpt4 book ai didi

javascript - 在 Ember.js 中获取路由列表

转载 作者:行者123 更新时间:2023-12-02 16:31:19 25 4
gpt4 key购买 nike

在我的主页(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()

问题是如何获取路线。我发现我可以通过以下方式获取路线名称列表:

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

但我不知道如何将它们转换为 Route 对象。据推测,Router 拥有执行此操作的信息,但 AFAICS 并未公开公开该信息。有什么建议么?

最佳答案

使用容器和查找怎么样?

Ember.keys(App.Router.router.recognizer.names).map(function(name) {
return App.__container__.lookup('route:' + name);
}).compact();

我知道您访问私有(private)的__container__。但通常情况下您不应该访问所有路由。

关于javascript - 在 Ember.js 中获取路由列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28274005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com