我正在使用 laravel 構建一個項目,我可以將記錄從數據庫獲取到我的模式中,但問題是每次我更新我的模式時,兩個選擇中的選項值也會隨著相同的獲取結果而增加。如何避免這種情況。在這里,我粘貼了編輯前后的兩張圖像以及我到目前為止所做的事情。請幫我完成它。之前的圖像后像我的模態部分<a href="javascript:void(0);" data-href="{{ url('admin/product_edit/'.$cat->id) }}" class="edit_product btn btn-sm btn-primary" data-toggle="modal" data-target="#editModal"> Edit</a><div class="modal" id="editModal" tabindex="-1" role="dialog" aria-labelledby="insertModalLabel" aria-hidden="true"> <div class="modal-dialog modal-lg" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title font-weight-bold" id="insertModalLabel">EditCustomer</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <p><b>Please note:</b> Fields marked with <span class="control-label"></span> is mandatory</p> <form action="{{ url('admin/update_product') }}" method="post" class="edit_database_operation"> @csrf <input class="form-control" type="hidden" name="eid" id="eid"> {{-- <input class="form-control" type="hidden" name="brand_id" id="brand_id"> <input class="form-control" type="hidden" name="category_id" id="category_id"> --}}
1 回答

楊__羊羊
TA貢獻1943條經驗 獲得超7個贊
在您的 jquery 代碼中,您可以使用.append()在選擇框中附加新選項,該選項只是將新元素插入到匹配元素集中每個元素的末尾。這就是它顯示雙值的原因。
相反,使用.html()替換選擇框中的所有元素。所以你只需要改變:
?$('#eproduct_brand').append(fb);
到
$('#eproduct_brand').html(fb);
你也這樣做eproduct_category
。
- 1 回答
- 0 關注
- 145 瀏覽
添加回答
舉報
0/150
提交
取消