【问题标题】:Foreach jQuery object in laravel bladelaravel刀片中的foreach jQuery对象
【发布时间】:2021-01-27 12:36:54
【问题描述】:

我正在增加 jQgrid 中项目的计数。我正在显示一个弹出窗口,它会打印一个包含所有项目的列表以及这些项目的数量。如何在表格中对这些项目进行 foreach?

jQuery:

let scannedCount = {};

function checkedFormatter(cellValue, row) {
    scannedCount[row.rowId] = 0;
    return '<div class="d-flex align-items-center justify-content-between checkCell" style="font-size: 1.8rem;">' +
        '<i class="fas fa-minus minCheck" style="cursor: pointer;" onclick="decrementCount(' + row.rowId + ')"></i> ' +
        '<input class="scannedCount-' + row.rowId + '" type="text" value="' + scannedCount[row.rowId] + '" style="width: 70px;">' +
        '<i class="fas fa-plus plusCheck" style="cursor: pointer;" onclick="incrementCount(' + row.rowId + ')"></i></div>'
}

function incrementCount(rowId) {
    scannedCount[rowId]++;
    $("#scannedCount-" + rowId).val(scannedCount[rowId]);
    console.log(scannedCount);
}

function shoppingCart(id) {
    openAddModal({
        type: 'shopping-cart',
        title: Lang.get('strings.shopping-cart'),
        url: '/' + id + '/shopping-cart/',
    });
}

购物车:

<div class="packing-slip">
    <table class="packing-table">
        <thead>
        <tr>
            <th class="table-head" style="text-align: left;">{{__('description')}}</th>
            <th class="table-head">{{__('amount')}}</th>
        </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
</div>
<script>
    {{$shoppingCart}} = scannedCount;
</script>

我是追加每一行还是什么?我无法让它工作。有人可以帮帮我吗?

谢谢

【问题讨论】:

    标签: jquery foreach jqgrid laravel-blade increment


    【解决方案1】:

    我在这里找到了答案Add table row in jQuery

    function shoppingCartItems() {
        $.each(scannedCount, function (key, value) {
            if (value > 0) {
                $('.packing-table > tbody:last-child').append('<tr><td>' + key + '</td><td>' + value + '</td></tr>');
            }
        })
    }
    

    【讨论】:

      猜你喜欢
      • 2017-06-20
      • 2018-04-04
      • 2021-10-19
      • 1970-01-01
      • 1970-01-01
      • 2022-09-22
      • 2015-12-15
      • 2017-11-13
      • 2019-12-26
      相关资源
      最近更新 更多