本文介绍了使用Javascript显示咆哮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Javascript在客户端显示咆哮。

I want to display a growl in client-side using Javascript.

我的意思是这个UI组件:

I mean this UI-component:

我发现这个,但是,我可以'找到一个名为的对象: topBar

I found this thread , However , I can't find an object called :topBar

还知道使用:

grep -rl 查找文件中的文字导致发现这个JS:

grep -rl to find text in files leads to discover this JS :

/**
 * PrimeFaces NotificationBar Widget
 */
PrimeFaces.widget.NotificationBar = PrimeFaces.widget.BaseWidget.extend({

    init: function(cfg) {
        this._super(cfg);

        var _self = this;

        //relocate
        this.jq.css(this.cfg.position, '0').appendTo($('body'));

        //display initially
        if(this.cfg.autoDisplay) {
            $(this.jq).css('display','block')
        }

        //bind events
        this.jq.children('.ui-notificationbar-close').click(function() {
            _self.hide();
        });
    },

    show: function() {
        if(this.cfg.effect === 'slide')
            $(this.jq).slideDown(this.cfg.effect);
        else if(this.cfg.effect === 'fade')
            $(this.jq).fadeIn(this.cfg.effect);
        else if(this.cfg.effect === 'none')
            $(this.jq).show();
    },

    hide: function() {
        if(this.cfg.effect === 'slide')
            $(this.jq).slideUp(this.cfg.effect);
        else if(this.cfg.effect === 'fade')
            $(this.jq).fadeOut(this.cfg.effect);
        else if(this.cfg.effect === 'none')
            $(this.jq).hide();
    },

    isVisible: function() {
        return this.jq.is(':visible');
    },

    toggle: function() {
        if(this.isVisible())
            this.hide();
        else
            this.show();
    }

});


推荐答案

你所指的组件是Growl,在客户端它由具有 renderMessage 函数来呈现单个咆哮消息。

The component you are referring to is Growl, in the client-side it's represented by PrimeFaces.widget.Growl which has renderMessage function to render a single growl message.

假设您已经使用widgetVar名称在页面中定义了一个growl组件:

Assuming you have already defined a growl component in your page with a widgetVar name:

<p:growl widgetVar="growlWV" />

现在使用javascript

Now in javascript

PF('growlWV').renderMessage({"summary":"summary goes here",
                             "detail":"detail goes here",
                             "severity":"warn"})

严重程度显然有三种类型:

The severity are obviously three types :


  • info

  • info

警告

错误

这篇关于使用Javascript显示咆哮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 11:47