1

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

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

1 回答 1

4

替换以下行:

$.gritter.removeAll();

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

于 2015-07-07T09:01:38.900 回答