用户反馈的SweetAlert2更新计数器

时间:2016-08-03 06:06:52

标签: javascript jquery sweetalert sweetalert2

有没有办法更新SweetAlert2警报上的文本,以显示在一个非常长的javascript循环中处理过的行数?不幸的是,人们一直离开页面,然后只有一半行被保存。

我以为我可以使用jQuery类型语法,但不确定正确的选择可能是什么。

$( '#rowsprocessed')文本(计数);

swal({
    title: 'Save Order.',  
    input: 'checkbox',                    
    inputValue: 0,
    inputPlaceholder: 'Remove Zero(s) Quantity Item(s) Before Saving the Order?',
    html: 'For large templates this may take a few moments. This message will automatically close when the process is complete.',
    type: 'info',
    showCancelButton: true,
    confirmButtonText: 'Submit',
    showLoaderOnConfirm: true,
    preConfirm: function(checkbox) {
        return new Promise(function(resolve, reject) {
            removeZeros = checkbox;

            setTimeout(function() { 
                swal.showLoading();
                $.post("/components/com_sails/views/neworderform/saveOrderHeader.php",
                        {
                            orderid: orderid,
                            accountid: accountid,
                            buyerid: buyerid,
                            vendorid: vendorid,
                            ponumber: ponumber,
                            specialinstr: specialinstr,
                            orderDate: orderDate,
                            shipDate: shipDate,
                            cancelDate: cancelDate
                        },
                        function (result) {
                            if (result.return == 1) {                           
                                // assign order id to holder field
                                $('#orderInput').jqxInput('val', result.ordernbr);

                                // loop through our rows and save depending on the removeZero marker
                                var rows = $('#jqxgrid').jqxGrid('getdisplayrows');
                                var rowsToRemove = [];
                                var linessaved = 0;


                                for (var i = 0; i < rows.length; i++) {
                                    var row = rows[i];

                                    // get row info for delete 
                                    if ((removeZeros == 1) && row['quantity'] == 0) {
                                        rowsToRemove.push(row.uid);
                                    }

                                    // run database update 
                                    $.ajax({
                                        type: 'POST',
                                        url: '/components/com_sails/views/neworderform/saveOrderLine.php',
                                    data: {
                                        orderid: result.ordernbr,
                                        removezeros: removeZeros,
                                        rowdata: row
                                    },
                                    success: function (rowSaveData) {
                                        // alert('rowSaveData ' + rowSaveData.return + " " + rowSaveData.isbn + "  " + rowSaveData.action + " " + rowSaveData.msg + " row.uid: " + row.uid);    
                                        // if there is a problem what do we do????

                                        if (rowSaveData.return == 1) {                                                          
                                            $('#rowsprocessed').text(i);

                                        }
                                        if (rowSaveData.return == -1) {
                                            // add to error message? 
                                        }

                                    },
                                    datatype: 'json',
                                    async: false});

                                }

                                if (removeZeros == 1) {
                                    // delete our zero rows 
                                    var commit = $("#jqxgrid").jqxGrid('deleterow', rowsToRemove);
                                    $('#jqxgrid').jqxGrid('render');
                                    lastselectedrow = -1;

                                }

                                // set save marker?? 
                                isDirty = false;

                            }
                            else {
                                // there was an error saving the header
                                // need to get this logged
                                alert('Error Saving Order. Details: ' + result.msg);
                            }

                        }, "json");

                resolve();

            }, 2000);
        });
    },
    allowOutsideClick: false
}).then(function() {
    swal({
        type: 'success',
        title: 'Order saved',   
        html: '<b><div id="rowsprocessed">0</div></b> rows saved.',
        timer: 4000
    });
})

1 个答案:

答案 0 :(得分:1)

当然,您可以使用Dictionary<string, string> values = new Dictionary<string, string> { { "abc", "Message 1" }, { "def", "Message 1" }, { "ghi", "Message 2" }, { "jkl", "Message 1" }, { "mno", "Message 2" }, { "pqr", "Message 3" }, { "aaa", null } }; var result = values.GroupBy(x => x.Value) // In this line the g.Key refers to the `Key` of the IGrouping and not // of the original dictionary. .ToDictionary(g => g.Key ?? string.Empty, // However, on this line each `item` is of the type // KeyValuePair and the `.Key` refers to the original's // dictionary's key g => g.Select(item => item.Key).ToList()) //Or: string.Join(", ", g.Select(item => item.Key)) .ToList(); foreach (var pair in result) { Console.WriteLine("{0}: {1}", string.Join(", ", pair.Value), pair.Key); } 传递一个可用作更新用户的方法的附加元素。

喜欢的东西:

{html: "..."}

然后使用此语法更新:

{
    ...
    html: 'For large templates this may take a few moments. This message will automatically close when the process is complete.<br/><span class="swal2-    status"></span>',
    ...
}

请参阅此处的示例: https://jsfiddle.net/1mvnxp3L/