简体   繁体   English

根据登录用户启用或禁用 Web Appbuilder 小部件

[英]Enable or disable Web Appbuilder widget based on logged user

In my web application I am able to add widgets and also change the rights of widgets from confing.json file,But this change is permanently.在我的 web 应用程序中,我可以添加小部件,还可以从 confing.json 文件更改小部件的权限,但此更改是永久的。 And I want the property of the widget to be enabled or disabled programatically at the run time using java-script API.Please suggest how to do it.我希望在运行时使用 java 脚本 API 以编程方式启用或禁用小部件的属性。请建议如何做。

It's possible.这是可能的。 Just publish an appConfig object with the new configuration using the appConfigChanged event name.只需使用appConfigChanged事件名称发布具有新配置的 appConfig object。

Here is a sample code that you could paste in chrome console to see it working with your Web AppBuilder project:这是一个示例代码,您可以将其粘贴到 chrome 控制台中,以查看它与您的 Web AppBuilder 项目一起使用:

var topic = require('dojo/topic')
function showWidget(widgetId, trueOrFalse) {
    var appConfig = getAppConfig();
    var widgetsFound = appConfig.widgetPool.widgets.filter( widget => widget.id === widgetId );
    if(widgetsFound.length > 1){
        throw Error('More than 1 widget with the same id ' + widgetsFound[0].id + '. ');
    }
    if(widgetsFound.length == 1){
        var widget = widgetsFound[0];
        widget.visible = trueOrFalse;
        topic.publish("appConfigChanged", appConfig, 'attributeChange', {});
    }
}

And then call:然后调用:

showWidget(yourWidgetId, false);

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

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