在laravel blade中Foreach jQuery对象



我正在为jQgrid中的一个项递增计数。我显示了一个弹出窗口,它打印了一个列表,其中包含所有项目以及这些项目的数量。如何在表格中预先处理这些项目?

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>

我是把每一行都加上还是什么?我不能让它工作。有人能帮帮我吗?

感谢

我在这里找到了ansare在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>');
}
})
}

最新更新