首页 > 解决方案 > 为什么每次删除行时表中的数据都会计算两次

问题描述

简单的 pos 系统 我在一个基本的 pos 系统中工作,我确实想从具有的订单详细信息表中删除订单项目(“项目代码、描述、单价、数量、总计”)。问题是当我删除我的行时,总数从小计中减去两次并给出错误的计算。我不明白为什么它会这样工作。如果有人可以帮助解决这个问题,真的很感激。谢谢你。

这是我的代码..

html代码-

 <div id="tblContainer" class="table-dark">
                    <table id="tblOrderDetails" class="table table-hover table-dark">
                        <thead>
                            <tr>
                                <th class="text-center">Item Code</th>
                                <th>Description</th>
                                <th>Unit Price</th>
                                <th class="text-center">Qty</th>
                                <th class="text-right">Total</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody id="orderdetailsbody">
                        
                        </tbody>
                    </table>
                </div>
                <div>
                    <span id="spnTotal">Total: <label id="lblTotal">0.0</label></span>
                    <button id="btnPlaceOrder" class="btn btn-primary"> <i class="fas fa-cart-arrow-down"></i>
                        Place Order</button>
                </div>

$("#tblOrderDetails tr td:last-child div").click(function(){

            var deleteQty = parseInt($(this).parent().parent().find("td:nth-child(4)").text());
            var deleteItem = $(this).parent().parent().find("td:first-child").text();
            
            for(i=0; i<ITEMS.length;i++){
                if(deleteItem == ITEMS[i].code){
                    ITEMS[i].qtyOnHand += deleteQty; 
                }
            }
            var newTotal = 0;
            var subTotal = parseFloat($("#lblTotal").text());
            var rowTotal = parseFloat($(this).parent().parent().find("td:nth-child(5)").text());
            newTotal = subTotal - rowTotal;
            $("#lblTotal").text(newTotal);

            $(this).parent().parent().fadeOut(500);
            var row = $(this).parent().parent();
            setTimeout(function(){
                row.remove();
            },600);

           });

标签: jqueryhtml-tablecalculated-columnsdelete-row

解决方案


推荐阅读