更新:现在,当我更改 poule_id 时,当我直接转到如下网址时,我会得到一个空表,里面什么也没有:
https://mydomaine.eu/go/public/competition/search/equipes?poule_id=2
我明白了:
表“\n\n\n\n\n”
我尝试创建一个函数来更改 Blade 表的结果,该 Blade 表用选择框显示装备(团队),但目前没有任何反应,我不知道我在哪里犯了错误,可能是在 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
这是我的 Controller :
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 函数中期望的 dataType 更改为 html,因为没有必要在 javascript 中转换为 json 并将其转换回 html。所以它看起来像这样:
您的 Controller :
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 是否到达服务器?
- 服务器是否将该调用路由到 Controller ?
- Controller 是否正确返回 View ?
- ajax 是否更新 dom 容器?
告诉我失败的地方,我将编辑更多信息。
关于javascript - 选择 onChange Table 边栏选项卡 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44677705/