diff --git a/Views/Master/KategoriSampah/Index.cshtml b/Views/Master/KategoriSampah/Index.cshtml index 2eb2c15..afe34f4 100644 --- a/Views/Master/KategoriSampah/Index.cshtml +++ b/Views/Master/KategoriSampah/Index.cshtml @@ -10,7 +10,7 @@
- @@ -158,35 +158,39 @@ // Open modal modal_tambah.showModal(); + loadJenisSampah(); }); + }); - // Get data for jenis sampah select + function openModal() { + modal_tambah.showModal(); + + // load dropdown setiap modal dibuka + loadJenisSampah(); + } + + function loadJenisSampah() { $.ajax({ url: '/Master/JenisSampah/table', // Ganti sesuai endpoint kamu method: 'GET', dataType: 'json', - success: function (response) { - var dropdown = $('#jenis_sampah'); + success: function (response) { + // Buat HTML option dengan map + let options = response.data + .map(item => ``) + .join(""); - // Hapus placeholder lama - dropdown.empty(); - dropdown.append(''); - - // Tambahkan item dari API - $.each(response, function (index, item) { - dropdown.append( - $(' + ${options} + `); }, error: function () { console.error('Gagal memuat data jenis sampah.'); } }); - }); + } function closeModal() { // Reset form