简体   繁体   English

AngularJS菜单是MEAN.js中的公共

[英]AngularJS Menu isPublic in MEAN.js

I'm creating a webapp using MEAN.js and I'm running into an issue with the nav menu. 我正在使用MEAN.js创建一个webapp,我遇到了导航菜单的问题。

There are a few questions that seem related to my issue, but none of the answers solve it for me, and it seems like most of them are attributed to a documentation error. 有一些问题似乎与我的问题有关,但没有一个答案可以解决它,而且似乎大多数问题都归因于文档错误。

I'm trying to set a menuItem to public, and this is how I am doing it in my core.client.config.js: 我正在尝试将menuItem设置为public,这就是我在core.client.config.js中执行的操作:

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

Everything specified works, even the ordering. 指定的一切都有效,甚至是订购。 However the public true parameter does not do anything. 但是,public true参数不起作用。

Currently I just set the entire topbar to isPublic in menus.client.service.js, but this is not ideal as I would like to control who can see what! 目前,我刚才设置的整个topbar的menus.client.service.js到isPublic,但这并不理想,因为我想控制谁可以看到什么!

this.addMenu('topbar', true);

Any help would be appreciated! 任何帮助,将不胜感激!

The problem lies in the public/modules/core/services/menus.client.service.js The shouldRender function, which is called for the menu, each item and sub-item, doesn't check for isPublic. 问题在于public / modules / core / services / menus.client.service.js为菜单调用的shouldRender函数,每个项目和子项目都不检查isPublic。 So just add: 所以只需添加:

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

and change the last line to: 并将最后一行更改为:

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

because otherwise the menu itself is never rendered. 因为否则菜单本身永远不会呈现。

Now you can call addMenuItem and addSubMenuItem like this: 现在你可以像这样调用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');

Note if you don't provide true or false, the menu-items are going to inherit from their parent. 请注意,如果您不提供true或false,则菜单项将从其父项继承。 As we set the menu to public every child is public. 当我们将菜单设置为公开时,每个孩子都是公开的。 As soon as we set a menu item private the children are also private. 一旦我们将菜单项设置为私有,孩子们也是私人的。

If you want to change the SubMenu visibility be careful with the amount of arguments. 如果要更改SubMenu可见性,请注意参数的数量。 The sixth argument has to be true. 第六个论点必须是真的。

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

^^ changes to vv ^^改为vv

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

You can of course change the functions signature to avoid this. 您当然可以更改功能签名以避免这种情况。 Just swap menuItemUIRoute and isPublic in menus.client.service.js 只需在menus.client.service.js中交换menuItemUIRoute和isPublic

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

Then you can add the SubMenu like this: 然后你可以像这样添加SubMenu:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM