简体   繁体   English

当从下拉列表中添加数据时,数据不应再出现在下拉列表中

[英]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.

相关问题 使用jQuery /纯jscript从HTML下拉列表(选择下拉列表时下拉列表)中获取事件数据 - Get event data from an HTML drop down list (the list that drops down when a drop down list is selected) using jQuery / plain jscript 从下拉列表中获取经过过滤的数据,并显示在另一个下拉列表中 - Fetch filtered data from the drop down list and present in another drop down list 删除数据时下拉列表中的空白 - White space in drop down list when data is removed 基于onchange下拉列表中的选择显示XML数据 - displaying XML data based on selection from a drop down list onchange 如何从动态数据下拉列表中显示选择选项 - How to display select option from dynamic data drop down list 如果没有数据来自json,则禁用html中的下拉列表 - make drop down list in html disabled if no data is coming from json 使用下拉列表选择 mvc 显示来自查询的数据 - Displaying data from a query using a drop down list selection mvc 使用下拉列表从mysql数据库中获取数据,然后使用搜索功能从选定的下拉列表选项中过滤数据 - Fetch data from mysql database using drop down list and then use search function to filter data from selected drop down list option 从下拉列表中选择元素时,从json文件加载数据 - Loading data from a json file when an element is selected from a drop down list ASP.Net (VB) - 使用上一个下拉列表中的数据填充下拉列表。 [未找到成员] - ASP.Net (VB) - Populate drop down list using data from previous drop down list. [Member Not Found]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM