Hi All,
I’m new to select2, this is my first try, I have a controller to get a list of timezones (see below), I want to list all of the timezones on my web page.
current problem: the list not showing
What I missed?
– my HTML
<select class="form-control select2" id="input-timezone" name="timezone"></select>
– js
$(function () {
$('#input-timezone').select2({
ajax: {
url: '/Tenants/Get_TimeZonesAsync',
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
},
placeholder: 'Search ...',
minimumInputLength: 1
});
});
– Controller returning list of timezone
{
"result": true,
"payload": [
{
"id": 0,
"text": "Africa/Abidjan",
"selected": false
},
{
"id": 1,
"text": "Africa/Accra",
"selected": true
},
{
"id": 2,
"text": "Africa/Addis_Ababa",
"selected": false
}
]
}