I'm having issues populating my list using select2. This is what I got this far. No errors in the browser debugger. Just returning "no results found". Any suggestions?
$(document).ready(function () {
//The url we will send our get request to
var attendeeUrl = '/Schedule/getCourses';
var pageSize = 20;
$(".test").select2({
ajax: {
url: attendeeUrl,
dataType: 'json',
delay: 250,
type: 'GET',
data: function (params) {
return {
searchTerm: params.term,
size: pageSize,
page: params.pageSize
};
},
processResults: function (data, params) {
params.page = params.page || 1;
return {
results: data.text
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; },
minimumInputLength: 1
});
});
I had to include the following.
templateResult: formatRepo,
templateSelection: formatRepoSelection
And the following functions.
function formatRepo(repo) {
if (repo.loading) return repo.text;
var markup = '<div class="asd">' + repo.CourseCode +
'</div>';
markup += '</div></div>';
return markup;
}
function formatRepoSelection2(repo) {
return repo.full_name || repo.text;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.