第二次删除后添加Gritter消息

时间:2015-01-01 17:19:52

标签: javascript jquery gritter

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

编辑:我发现该问题属于$.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');
});

1 个答案:

答案 0 :(得分:3)

替换以下行:

<强> $ gritter.removeAll();

使用

<强> $( 'gritter项目的包装器。')除去();