[英]when data added from drop down list the data should no longer be in drop down list
i am trying to show only those countries name from drop down list which doesn't exist in database, for example if i add 'Bottles' to database the value 'Bottles' should no longer be in drop down list.我试图从下拉列表中仅显示数据库中不存在的那些国家/地区名称,例如,如果我将“瓶子”添加到数据库中,则“瓶子”值不应再出现在下拉列表中。
form.indx表格索引
<div class="form-group" id="frm_packages">
<select class="form-control" id="packages" name="packages"title="packages">
<option value="Pack">Pack</option>
<option value="Bottles">Bottles</option>
<option value="Cartons">Cart</option>
<option value="Boxes">Boxes</option>
<option value="Cans">Cans</option>
<option value="Bags">packages</option>
</select>
<div class="d-inline"></div>
</div>
//scripts show data //脚本显示数据
var table = $('#packageTable').DataTable({
dom: 'Bfrtip',
aaSorting: [[2, 'asc']],
stateSave: true,
processing: true,
serverSide : false,
bSortable: true,
responsive : true,
autoWidth : false,
order: [[0, 'desc']],
buttons: [
'create', 'print', 'reload'
],
ajax: '{{route('admin.packages.index')}}',
columns: [
{data: 'id', name: 'id'},
{data: 'name', name: 'name'},
],
});
//Adding new data //添加新数据
$(document).on('click','#btnSave', function(e){
e.preventDefault();
$.ajax({
url: "{{ route('admin.packages.store') }}",
type: 'POST',
dataType: 'json',
data: {
name: $('#packages').val(),
},
success:function(data){
if (data.status == true) {
$('#new').modal('hide');
frm.trigger('reset');
table.ajax.reload( null, false );
Toast.fire({
type: 'success',
title: 'added successful'
})
}
},
});
});
//Controller //控制器
public function index(PackageDataTable $dataTable)
{
return $dataTable->render('admin.packages.index');
}
public function store(Request $request)
{
request()->validate(['name'=>['required','unique:packages'],]);
Package::create(request()->all());
return response()->json(array("status"=>true));
}
//model //模型
protected $fillable = ['name'];
public function products()
{
return $this->belongsToMany(Product::class)
}
what should i do for not showing the existing data in drop down list我应该怎么做才能在下拉列表中不显示现有数据
Initially, you should fetch all your data and then you must assign it to the js
variables one by one because javascript
is the language which will work for you on the client-side on your page.最初,您应该获取所有数据,然后必须将其一一分配给
js
变量,因为javascript
是适用于您页面客户端的语言。 And then finally for the dropdown by applying if{}
, else{}
conditions you can get the desired results.最后,通过应用
if{}
和else{}
条件,您可以获得所需的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.