From 21849076dc70092804d1a84762ac9e571d2ca53f Mon Sep 17 00:00:00 2001 From: Kevin Hendrawan Date: Fri, 21 Nov 2025 23:34:17 +0700 Subject: [PATCH] fix(MasterKategoriSampah): load data dropdown from JenisSampah json --- Views/Master/KategoriSampah/Index.cshtml | 40 +++++++++++++----------- 1 file changed, 22 insertions(+), 18 deletions(-) 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