Select onChange Table blade 查看

Select onChange Table blade view

更新:现在,当我更改 poule_id 时,我得到一个空白的 table,里面什么也没有,当我直接进入 url 时,例如:

https://mydomaine.eu/go/public/competition/search/equipes?poule_id=2

我得到:
table“\n\n\n\n\n”

我尝试创建一个函数来更改 blade table 的结果,后者使用 select 框显示装备(团队),但目前我没有任何反应不知道我哪里做错了,可能是在 javascript 代码

希望有人能帮助解决这个问题,非常感谢

我尝试根据 poule_id 更改我的 table,使用 select 框,如下所示:

<select id="poule">
    @foreach($select_poules as $select_poule)
        <option value="{{$select_poule->id}}">{{$select_poule->lb_poule}}</option>
    @endforeach
</select>

我的 table 包含依赖 poule_id 的团队:

@foreach($equipes as $equipe)
  <tr>
    <td>
      <a href="{!! route('club.show', $equipe->equipe->structure->id) !!}">{{$equipe->equipe->structure->nom_structure}}</a>
    </td>
    <td>
      <a href="{!! route('equipe.show', $equipe->equipe->id) !!}">{{$equipe->equipe->lb_equipe}}</a>
    </td>
    <td>
      {!! Form::text('nb_bonus') !!}
    </td>
  </tr>
@endforeach

这是我的控制器:

public function searchEquipes(Request $request)
{

    if ($request->has('poule_id')) {

        $equipes = EquipePoule::where('poule_id' , $request->poule_id)->get();

        $competition = Compet::where('id' , 1)->first();

        $categorie_compet = CategorieCompet::pluck('lb_categorie_compet' , 'id');

        $categorie_age = CatgEquipe::pluck('lb_catg_equipe' , 'id');

        $structure_rattachement = Structure::select('num_structure', 'nom_structure' , 'id')
            ->where('type_structure_id' , '1')
            ->orWhere('type_structure_id' , '2')
            ->orWhere('type_structure_id' , '3')
            ->get()
            ->mapWithKeys(function($i) {
                return [$i->id => $i->num_structure.' - '.$i->nom_structure];
            });
        $poules = Poule::where(['compet_id' => $competition->id])->get();

        $rencontres = Rencontre::where(['compet_id' => $competition->id])->orderBy('dt_rencontre' , 'DESC')->get();

        $designations = RencontreOfficiel::where(['compet_id' => $competition->id])->get();

        $classements = Classement::where(['compet_id' => $competition->id])->orderBy('nb_point_classement' , 'DESC')->get();

        $equipe_to_select = Equipe::select('lb_equipe', 'structure_id' , 'catg_equipe_id' ,'id')
            ->get()
            ->mapWithKeys(function($i) {
                return [$i->id => $i->lb_equipe.' - '.$i->structure->nom_structure.' - ' .$i->catg_equipe->lb_catg_equipe];
            });

        $stade = Stade::select('lb_nom', 'ville_stade' ,  'cd_post_stade' ,  'id')
            ->get()
            ->mapWithKeys(function($i) {
                return [$i->id => $i->lb_nom.' - '.$i->ville_stade.' - '.$i->cd_post_stade];
            });



        $find_equipes = $competition->equipes;

        $domicile = $find_equipes->mapWithKeys(function ($i) {
            return [$i->id => $i->lb_equipe.' - '.$i->structure->nom_structure.' - ' .$i->catg_equipe->lb_catg_equipe];
        });


        //ON AFFICHE QUE LES EQUIPES ENREGSITRER DANS LE COMPETITION
        $find_equipes = $competition->equipes;
        $visiteur = $find_equipes->mapWithKeys(function ($i) {
            return [$i->id => $i->lb_equipe.' - '.$i->structure->nom_structure.' - ' .$i->catg_equipe->lb_catg_equipe];
        });

        $select_poules = Poule::where('compet_id' , 1)->get();

        $journees = Journee::where('compet_id' , 1)->get();

        $journee_to_select = Journee::where('compet_id' , 1)->pluck('nm_journee' , 'id');


        return response()->json([

            'table' => view("competitions/show", compact('equipes' , 'competition' , 'categorie_age' , 'categorie_compet' , 'classements' , 'equipe_to_select' , 'structure_rattachement' , 'poules' , 'select_poules' , 'journee_to_select' , 'journees' , 'rencontres', 'designations' , 'stade', 'domicile' , 'visiteur'))->render(),

        ]);

    }else {

        echo 'on trouve rien ';
    }

这是我的javascript:

<script>
    $('#poule').change(function () {
        $.ajax({
            type: 'GET',
            dataType: "json",
            url : 'search/equipes/',
            data : {
                poule_id : document.getElementById('poule').value
            },
            success:function(data){
                $('#equipes').html(data.table);
            },
        });
    });
</script>

没有错误反馈很奇怪,但我会首先将 ajax 函数中的数据类型更改为 html,因为没有必要强制转换为 json 并且在 javascript 中将其转换回 html 一次。所以它看起来像这样:

您的控制器:

public function searchEquipes(Request $request)
{
    if ($request->has('poule_id')) {
        $equipes = $equipes = EquipePoule::wherePouleId($request->poule_id)->get();
        return view("competitions/show", compact('equipes'))->render();
    }
}

你的ajax:

<script>
    $('#poule').change(function () {
        $.ajax({
            type: 'GET',
            dataType: "html",
            url : 'search/equipes/',
            data : {
                poule_id : document.getElementById('poule').value
            },
            success:function(data){
                $('#equipes').html(data);
            }
        });
    });
</script>

然后我会按照一些步骤来检查失败的地方:

  • 活动是否到达ajax?
  • ajax 是否到达服务器?
  • 调用控制器的是服务器路由吗?
  • 控制器是否正确返回视图?
  • ajax 是否正在更新 dom 容器?

告诉我失败的地方,我会编辑更多信息。