This belong to codes prior to select2 version 4
I have a simple code of select2 that get data from ajax
select2
Sometimes, select2() will be loading firstly, and that makes the control not to show previously selected value correctly. Putting a delay for some seconds can resolve this problem.
select2()
setTimeout(function(){ $('#costcentreid').select2(); },3000);