我使用select2进行了多选输入下拉菜单。但是,我真的不确定如何从下拉列表中的数据库中获取我调用的数据,以便可以在数据表中查看它。这是我的代码:
用于输入下拉菜单select2的脚本:
$('.ethnicity').select2({
placeholder: 'Select..',
ajax: {
url: '/select2-autocomplete-ajax_ethnicity',
dataType: 'json',
delay: 250,
processResults: function ($ethnicity) {
return {
results: $.map($ethnicity, function (item) {
return {
text: item.Bangsa_updated,
id: item.id,
}
})
};
用于输入下拉菜单的控制器,因此它将选择键入的输入:
public function ethnicity(Request $request)
{
$ethnicity = [];
if($request->has('q')){
$search = $request->q;
$ethnicity = DB::table("user")
->select("id","ethnic")
->where('ethnic','LIKE',"%$search%")
->get();
}
return response()->json($ethnicity);
}
以上代码仅用于从数据库中选择数据,而无需将数据提取到数据表中。 下面的控制器将数据捕获到数据表中(我将其用于简单的下拉菜单,但是不知道如何更改,因此对于上面的输入下拉菜单很有用。
public function fnFilter(Request $request)
{
if(request()->ajax())
{
if(!empty($request->dataGender))
{
$data = DB::table('user')
->select('id', 'Fn', 'Ln')
->where('ethnic', $request->ethnicity)
->get();
}
else
{
$data = DB::table('user')
->select('id', 'Fn', 'Ln', 'Umur', 'Phone', 'Dob','St', 'Country','Zip','Ct','Jantina')
->get();
}
return datatables()->of($data)->make(true);
}
$dataName = DB::table('modified_dpprs')
->select('ethnic','Jantina')
->groupBy('ethnic')
->orderBy('ethnic', 'ASC')
->get();
return response()->json($dataName);
刀片是:
<select id="ethnicity" class=" ethnicity form-control select2-allow-clear" style="width:200px;" name="namaDUN" multiple >
<option value="">Select</option>
我的想法是将控制器函数种族的结果放入函数fnFilters中。但是我不知道该怎么办。
答案 0 :(得分:0)
$ docker images | awk -t '{print $7}'| grep MB | awk -F 'M' '{print $1}{s+=$$1}END{print s}'