JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
JavaScript
function renderLevels() {console.log("render levels");}
function renderAlerts() {console.log("render alerts");}
function cb() {console.log("callback");}
var cbInfo = [
{
templatePath: '/echo/json/',
callback: renderLevels
},
{
templatePath: '/echo/json/',
callback: renderAlerts
}
];
function loadTemplates(cbInfo, cb) {
var ajaxes = [],
callbacks = [];
cbInfo.forEach(function (elem) {
ajaxes.push($.ajax({type: "GET", url: elem.templatePath}));
callbacks.push(elem.callback)
});
$.when(ajaxes).then(
function () {
var args = Array.prototype.slice.call(arguments);
callbacks.forEach(function (elem, index) {
elem(args[index]);
});
cb();
},
function () {
// failure
console.error("loadTemplates() : could not load UI templates.")
}
);
}
loadTemplates(cbInfo, cb)