@foreach($boxes as $idx => $box)
<tr class="data_row" data-id="{{ $box->id }}">
<td class="table_fix">{{ $boxes->firstItem() + $idx }}</td>
<td class="table_fix"><input class="form-check-input" type="checkbox" name="box_ids[]" value="{{ $box->id }}"></td>
<td>{{ $box->barcode }}</td>
<td>{{ $box->descr }}</td>
<td>{{ $box->packs->count() }}</td>
<td>{{ $box->packs->pluck('item_id')->unique()->count() }}</td>
<td>{{ $box->packs->sum('pack_qty') }}</td>
<td><button type="button" id="pack_box_info_btn" class="btn btn-primary" onclick="this.blur();">{{__('박스 정보')}}</button></td>
</tr>
@endforeach
.closest()
메서드는 jQuery에서 사용되며, 주어진 선택자에 가장 가까운 상위 요소를 찾습니다. .closest()
메서드를 호출한 요소부터 상위 요소로 거슬러 올라가며, 가장 먼저 주어진 선택자와 일치하는 첫 번째 상위 요소를 반환합니다.
// 클릭한 버튼을 감싸는 상위 요소에서 관련된 data-id를 찾음 var boxId = $(this).closest('.data_row').data('id'); var data = { boxId: boxId };
alternateBarcodeId: curRow.find('input[name="detail[${lastId}][alternate_barcode]"]').val()
예를 들어
$("#commonModal .modal-title").html('Mix Rule'); => #commonModal.modal-title << 붙여쓰면 두 가지를 공통으로 가진 셀렉터를 찾는 것 #commonModal .modal-title << 띄어쓰면 #아이디를 가진 부모 태그 안에 있는 .클래스를 찾는 것