0
このホテルのウェブサイトは、都市のホテルを見るためのユーザー検索の後、予約ホテルです。作成方法Laravel 5.2でリモートデータ検索をロードするには?
私はlaravel 5.2でリモートデータを読み込みますselect2を使用します。
Githubの例:https://select2.github.io/examples.html#data-ajax
モデルCity
:
protected $fillable = [
'name', 'state', 'country', 'status'
];
モデルHotel
:
protected $fillable =[
'name', 'address', 'phone', 'status', ...
];
HTML:
<select class="js-data-example-ajax">
<option value="3620194" selected="selected">select2/select2</option>
</select>
スクリプト:ajax
からの送信データの後Laravel controller
に書き込む方法
$(".js-data-example-ajax").select2({
ajax: {
url: "https://api.github.com/search/repositories",
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, params) {
// parse the results into the format expected by Select2
// since we are using custom formatting functions we do not need to
// alter the remote JSON data, except to indicate that infinite
// scrolling can be used
params.page = params.page || 1;
return {
results: data.items,
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 1,
templateResult: formatRepo, // omitted for brevity, see the source of this page
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
});
?
はどうもありがとう、私は見てみたいです都市とホテルを一緒に検索した後 – mySun