【问题标题】:Is there any way to get a list of child states in angular-ui-router?有没有办法在 angular-ui-router 中获取子状态列表?
【发布时间】:2014-02-13 08:17:46
【问题描述】:

我正在构建一个角度应用程序,对于应用程序的一部分,我希望有一个菜单,其中包含根据可用状态动态填充的选项。这是我的状态配置的简化部分:

$stateProvider.state('root.type.list.controls', {
  url: '/controls',
  templateUrl: 'views/controls.html',
  controller: 'ControlsCtrl',
  data: {
    title: 'Controls'
  }
})
.state('root.type.list.items', {
  url: '/items',
  templateUrl: 'views/items.html',
  controller: 'ItemsCtrl',
  data: {
    title: 'Items'
  }
})

我希望能够根据配置的data 部分中的内容,使用'root.type.list' 状态的每个直接子级的标题填充下拉菜单。有什么方法可以获取特定状态的所有子状态列表?

【问题讨论】:

    标签: javascript angularjs angular-ui angular-ui-router


    【解决方案1】:

    最终使用 $state.get() 并执行以下操作:

    function _children(stateName) {
      return _.filter($state.get(), function(config) {
        return stateName === config.name.slice(0, stateName.length) &&
          config.name.split('.').length === stateName.split('.').length + 1;
      });
    }
    

    【讨论】:

      猜你喜欢
      • 2015-12-18
      • 2018-05-01
      • 2013-05-14
      • 2014-12-15
      • 1970-01-01
      • 1970-01-01
      • 2015-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多