Hi, I have been struggling with this issue for a while. Basically I need to initialize an avatar image once html is rendered in the dropdown after user has entered a query.
$(".js-select2").select2({
placeholder: "Search active connections",
theme: "material",
templateResult: formatState,
ajax: {
url: '/connections/active',
dataType: 'json',
data: function (params) {
var query = {
q: {full_name_or_email_cont: params.term},
}
return query;
}
}
})
function formatState (state) {
if (!state.id) {
return state.text;
} // image html string created but not added to dom yet
var $state = $(`<span> ${state.avatar} ${state.text} </span>`);
// need to run this to render avatar otherwise image doesnt appear but have to wait until results are populated
$('.initialjs-avatar').initial({
radius: 30
});
return $state;
};
Essentially I am looking for a event that wil fire after new results have been appended to ul element. I have tried open and select but those are after the results have already appeared. Thank you.