My problem is a bit hard to explain, but I'll try my best. I have 3 tabs, one of which is active by default. Every time a tab is activated, an event fires. However, the tab headings are set in a function set earlier. My code is given below:
<script>
var queues = {};
$(document).ready(function(){
getQueueData();
$('.nav a[href="#queue1"]').tab('show');
});
function getQueueData(){
$.post('interface/getqueues.php', function(data){
var str = "#q";
for (var i=0; i<data.data.length; i++){
str += i;
$(str).text(data.data[i]["name"]);
queues[str] = data.data[i];
console.log(queues[str]);
str = "#q";
}
});
}
$('a[data-toggle="tab"]').on("shown.bs.tab", function(event){
console.log("HELLO WORLD!");
var elem = $(this).attr("id");
var id = "#"+elem;
console.log(queues);
});
</script>
Now, the getQueueData() function should execute BEFORE the shown.bs.tab
event is fired. This is necessary for the latter event to be able to access the values in the queues
object. In fact, however, when the page is loading, the shown.bs.tab
function is executing first, followed by getQueueData(). This means that in the shown.bs.tab
method, queues
is undefined the first time. I know it because the HELLO WORLD and an empty object is printing in the log before the console.log(queues[str])
output. Does anyone know how I can make the getQueueData() execute completely before going to the 'shown.bs.tab'
event?