AngularJS菜单在MEAN.js中是公开的

AngularJS Menu isPublic in MEAN.js

本文关键字:js 菜单 MEAN AngularJS      更新时间:2023-09-26

我正在使用 MEAN 创建一个 Web 应用程序.js并且我在导航菜单上遇到了问题。

有几个问题似乎与我的问题有关,但没有一个答案为我解决它,似乎其中大多数都归因于文档错误。

我正在尝试将菜单项设置为公共,这就是我在core.client.config.js中的做法:

Menus.addMenuItem('topbar', 'About Us', 'about', 'item', '/about', true, null, 1);

指定的所有内容都有效,甚至排序也是如此。但是,公共true参数不执行任何操作。

目前,我只是在menus.client.service.js中将整个topbar设置为isPublic,但这并不理想,因为我想控制谁可以看到什么!

this.addMenu('topbar', true);

任何帮助将不胜感激!

问题出在 public/modules/core/services/menus.client.service.js为菜单、每个项和子项调用的 shouldRender 函数不检查 isPublic。所以只需添加:

// A private function for rendering decision 
var shouldRender = function(user) {
    if(this.isPublic){
        return true;
    }
    ...
}

并将最后一行更改为:

//Adding the topbar menu
this.addMenu('topbar', true);

因为否则菜单本身永远不会呈现。

现在你可以像这样调用addMenuItem和addSubMenuItem:

Menus.addMenuItem('topbar', 'Articles', 'articles', 'dropdown', '/articles(/create)?', <true/false>);
Menus.addSubMenuItem('topbar', 'articles', 'List Articles', 'articles');
Menus.addSubMenuItem('topbar', 'articles', 'New Article', 'articles/create');

请注意,如果您不提供 true 或 false,则菜单项将从其父项继承。当我们把菜单设置为公开时,每个孩子都是公开的。一旦我们将菜单项设置为私有,孩子们也是私有的。

如果要更改子菜单可见性,请注意参数的数量。第六个论点必须为真。

Menus.addSubMenuItem('topbar', 'articles', 'List Articles', 'articles');

对 VV 的^^更改

Menus.addSubMenuItem('topbar', 'articles', 'List Articles', 'articles', '/articles', true);

当然,您可以更改函数签名以避免这种情况。只需在menus.client.service中交换menuItemUIRoute和isPublic.js

 // Add submenu item object
this.addSubMenuItem = function(menuId, rootMenuItemURL, menuItemTitle, menuItemURL, isPublic, menuItemUIRoute, roles, position) {
    // Validate that the menu exists

然后你可以像这样添加子菜单:

Menus.addSubMenuItem('topbar', 'articles', 'List Articles', 'articles', true);