gpt4 book ai didi

javascript - 如何在抽象父级的子状态下使用 ncy-breadcrumb

转载 作者:行者123 更新时间:2023-11-28 00:10:48 38 4
gpt4 key购买 nike

我是 AngularJS 新手,我使用过 ncy-breadcrumb对于我的 AngularJS 项目。有一个抽象的真实父状态和它的两个子状态。我将这些子状态用于选项卡。但我找不到一种方法来动态地在面包屑中显示这些状态。我唯一能做的就是将一个子状态名称硬编码为其他状态的父状态。但我需要一个解决方案来动态显示 collectionsWorkPage 状态中的这些子状态。

.state('collectionsLibrary', {
url: '/headquarters/collections-library/',
templateUrl: 'app/views/collectionsLibrary/base.html',
controller: 'CollectionsLibraryBaseController',
ncyBreadcrumb: {
label: 'Collections Library',
parent: 'headquarters'
},
abstract: true,
resolve: {
controller: function ($q) {
var deferred = $q.defer();
require(['controllers/collectionsLibrary/CollectionsLibraryBaseController'], function () {
deferred.resolve();
});
return deferred.promise;
}
}
})

.state('collectionsLibrary.available', {
url: 'available/',
templateUrl: 'app/views/collectionsLibrary/available.html',
controller: 'CollectionsLibraryAvailableController',
ncyBreadcrumb: {
label: 'Collections Library-Available',
parent: 'headquarters'
},
resolve: {
controller: function ($q) {
var deferred = $q.defer();
require(['controllers/collectionsLibrary/CollectionsLibraryAvailableController'], function () {
deferred.resolve();
});
return deferred.promise;
}
}
})

.state('collectionsLibrary.my', {
url: 'my/',
templateUrl: 'app/views/collectionsLibrary/my.html',
controller: 'CollectionsLibraryMyController',
ncyBreadcrumb: {
label: 'Collections Library-My',
parent: 'headquarters'
},
resolve: {
controller: function ($q) {
var deferred = $q.defer();
require(['controllers/collectionsLibrary/CollectionsLibraryMyController'], function () {
deferred.resolve();
});
return deferred.promise;
}
}
})

.state('collectionsWorkPage', {
url: '/headquarters/collections-library/:id/edit/',
templateUrl: 'app/views/collectionsWorkPage.html',
controller: 'CollectionsWorkPageController',
ncyBreadcrumb: {
label: 'Edit Collection',
parent: 'collectionsLibrary.available'
},
params: {
data: {}
},
resolve: {
controller: function ($q, $stateParams) {
var deferred = $q.defer($stateParams);
require(['controllers/CollectionsWorkPageController'], function () {
deferred.resolve();
});
return deferred.promise;
}
}
})

最佳答案

parent 属性可以是字符串,也可以是返回父名称的函数。该函数提供当前状态 Controller 的范围(与标签插值相同)。

所以你可以这样做:

ncyBreadcrumb: {
label: 'Edit Collection',
parent: function($scope) {
if($scope.tab === 'MY') // Constant defined in CollectionsLibraryMyController
return 'collectionsLibrary.my';
else if($scope.tab === 'AVAILABLE') // Constant defined in CollectionsLibraryAvailableController
return 'collectionsLibrary.available';
}
}

参见API reference了解更多详情

关于javascript - 如何在抽象父级的子状态下使用 ncy-breadcrumb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30905511/

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