我有一个有一些城市的模态。如果用户点击了一个城市,那么在#conferences div中,会出现在" city"列中的会议。点击了城市。这很好。
我怀疑的是,如果用户点击国家而不是城市,如何独立于城市点击所有会议,因为如果用户点击国家,结果可以是任何城市。
你知道如何实现这个目标吗?
使用&#34;&#34;等值属性&#34; <a value="">Country</a>
&#34;当&#34;国家&#34;在控制台中单击出现:
&#34; {message: "", "exception: "Symfony\Component\HttpKernel\Exception\NotFoundHttpException",…}" in file "/Illuminate/Routing/RouteCollection.php
&#34;
ConferenceController方法获取点击城市的会议:
public function getConferencesOfCity($slug)
{
$conferences = Conference::whereCity($slug)->get();
return response()->json($conferences);
}
城市链接出现的模式:
<div class="modal-body">
<div class="container">
<ul class="modal-list row">
<li class="col-lg-4 col-md-6 col-sm-12">
<a class="" name="" id="" value="">Country</a>
</li>
@foreach($cities as $city)
<li class="col-lg-4 col-md-6 col-sm-12">
<a class="" name="city" id="{{$city}}">{{$city}}</a>
</li>
@endforeach
</ul>
</div>
</div>
路线:
Route::get('conferences/where/city/{slug}','ConferenceController@getConferencesOfCity')->name('city.conferences');
jQuery ajax请求:
$("a[name='city']").on('click', function(){
$('#showCities').html($(this).text());
var city = $(this).attr("id");
$.ajax({
url: '{{ route('city.conferences',null) }}/' + city,
type: 'GET',
success:function(result){
console.log(result)
$('#conferences').empty();
var newConferences='';
var placeholder = "{{route('conferences.show', ['id' => '1', 'slug' => 'demo-slug'])}}";
$.each(result, function(index, conference) {
$('#modal2').modal('hide');
var url = placeholder.replace(1, conference.id).replace('demo-slug', conference.slug);
newConferences += '<div class="col-12 col-sm-6 col-lg-4 col-xl-3 mb-4">\n' +
' <h5 class="card-title">'+conference.name+'</h5>\n' +
<p class="card-text font-size-sm">'+conference.city+'</p>\n' +
' </div>\n';
});
$('#conferences').html(newConferences);
},
error: function(error) {
console.log(error.status)
}
});
});