【问题标题】:Adding Gritter Message After Second Deletion在第二次删除后添加 Gritter 消息
【发布时间】:2018-01-02 18:22:42
【问题描述】:

我试图找出为什么当用户通过单击 ajax-delete 类图标被删除并执行删除过程时,它会在删除后显示 gritt 消息,但是如果您之后要立即删除另一个用户,它会删除以前的 grutter 消息,但没有显示第二次删除的另一个消息。关于为什么会这样的任何想法?

编辑:我发现问题属于$.gritter.removeAll(); 代码行。当有另一个现有通知时,它会删除它但不添加下一个通知。

任何想法我应该在这里做什么?

var rowToDelete = null;
var basicTable = null;
var api_url = null;

$(document).ready(function() {});

$(document).on('click', '.ajax-delete', function(e)
{
    console.log(basicTable);
    e.preventDefault();
    //defining it like this captures and optimizing the need to cycle over the DOM more than once
    //in subsequent calls to the element specifically
    $elem = $(this);
    $parentElem = $elem.closest('tr');
    rowToDelete = $parentElem.get(0);
    api_url     = $elem.attr('href');
    runConfirmation($('td:eq(1)', $parentElem).text());
});

function runConfirmation(nameSting)
{
    $mymodal = $('#myModal');
    $('.modal-body p', $mymodal).html('Are you sure you want to delete this <strong>'+nameSting+'</strong>?');
    $mymodal.modal('show');
}

$('#myModalConfirm').on('click', function(e) {
    $.ajax({
        type: 'post',
        url: api_url,
        data: { _method: 'DELETE' },
        dataType: 'json',
        success: function(response) {
            $.gritter.removeAll();
            var className = 'growl-danger';
            if (response.status == "SUCCESS") {
                className = 'growl-success';
                basicTable.fnDeleteRow(basicTable.fnGetPosition(rowToDelete));
                rowToDelete = null;
                api_url     = null;
            }
            $.gritter.add({
                position: 'top-right',
                fade_in_speed: 'medium',
                fade_out_speed: 2000,
                time: 6000,
                title: response.title,
                text: response.message,
                class_name: className,
                sticky: false
            });
        }
    });

    $('#myModal').modal('hide');
});

【问题讨论】:

    标签: javascript jquery gritter


    【解决方案1】:

    替换以下行:

    $.gritter.removeAll();

    $('.gritter-item-wrapper').remove();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-07
      • 2016-08-30
      相关资源
      最近更新 更多