I use Select2 and Ajax successfully to invoke the template command, but how do I change this to use the template command but remove the Ajax request i.e. use a array variable.
$(document).ready(function() {
var $contact2 = $(".contact2");
$.ajax({
url: '{{ url('/') }}' + '/api/opportunitycontacts/' + {{ $opportunity->id }},
type: 'GET',
dataType: 'json',
async: true,
success: function(data) {
$contact2.select2({
maximumSelectionLength: 1,
data: data,
templateSelection: function(result) {
return result['text'];
},
templateResult: function(result) {
if (!result['id']) {
return result['text'];
};
var final =
'<div>' +
'<strong>' + result['text'] + '</strong>' +
'<ul class="list-unstyled">' +
'<li><em>' + result['job_title'] + '</em></li>' +
'<li><em>' + result['facility'] + '</em></li>' +
'</ul>' +
'</div>';
return final;
},
escapeMarkup: function(result) {
return result;
},
});
}
});
});