EmberJS中嵌套路由的状态 [英] State of nested routes in EmberJS

查看:139
本文介绍了EmberJS中嵌套路由的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的路由结构:

I have a route structure like this:

this.resource('A',function(){
  this.resource('B',function(){
    this.route('C');
  });
});

有没有办法可以查看 A ,其中 B 的嵌套路线目前处于活动状态?

Is there a way I can check in A, which nested route of B is currently active?

由于可用性原因,我在 A ,它还包含 BC B.index 的链接但我只需要显示这两个链接之一。

For usability reasons I have a navigation in A, which also holds links for B.C and B.index But I only want to show one of those two links.

推荐答案

应用程序控制器上有一个属性 currentPath 。您可以使用它来查找当前路由器中的哪条路径。这是整个路径,所以它将是 ABC ABindex

The application controller has a property on it currentPath. You can use that to find out which path in the router you're currently on. It's the entire path, so it'd be A.B.C or A.B.index.

App.ColorsController = Ember.ArrayController.extend({
  needs:'application',
  atIndex: Em.computed.equal('controllers.application.currentPath', 'colors.index')
});

示例: http://emberjs.jsbin.com/nobima/2/edit

这篇关于EmberJS中嵌套路由的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆