gpt4 book ai didi

javascript - 第二次删除后添加 Gritter 消息

转载 作者:行者123 更新时间:2023-11-30 10:08:37 24 4
gpt4 key购买 nike

我试图找出为什么当通过单击 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');
});

最佳答案

替换以下行:

$.gritter.removeAll();

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

关于javascript - 第二次删除后添加 Gritter 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27732909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com