选择onChange Table刀片视图

时间:2017-06-21 13:35:23

标签: javascript laravel blade

更新:现在当我更改poule_id时,我得到一张内部没有任何内容的空白表,当我直接转到网址时:

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

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

我尝试创建一个更改我的刀片表的结果的函数,他们使用选择框显示equipes(团队)但是目前没有任何事情我不知道我在哪里犯了错误,它可能在javascript代码中

希望有人可以帮助解决这个问题,非常感谢提前

我尝试使用像这样的选择框取决于poule_id来更改我的表:

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

我的表包含依赖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>

1 个答案:

答案 0 :(得分:1)

获取没有错误反馈是非常奇怪的,但我会首先将你期望的ajax函数中的dataType更改为html,因为没有必要在javascript中强制转换为json并将其强制转换为html。所以它看起来像这样:

你的控制器:

return base.OnBackButtonPressed();

你的阿贾克斯:

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?
  • ajax是否到达服务器?
  • 服务器是否路由调用控制器?
  • 控制器是否正确返回视图?
  • ajax是否更新了dom容器?

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

相关问题