I have this part of the code that doesn't work. It suppose to make a part of a tree view. The callback for the klassification_ajax should work after the function is done, but cause of the other ajax calls in different iteration of the while loop, then it doesn't work at all. I checked If I had just one iteration, it works cause it doesn't interfere with other ajax calls, but when it goes for the second iteration, they happen simultaneously and as the result none of them work. then I realized I should have make those iterations as a nested callback to make it work step by step, but HOW ?????
var j = 2;
while (result['klass-' + j]) {
klass_id = result['klass-' + j];
if (handled_klass.indexOf(result['klass-' + (j - 1)]) == -1) {
handled_klass.push(result['klass-' + (j - 1)]);
klassification_ajax(result['klass-' + (j - 1)], function () {
$('#all-klassifikation-' + result['klass-' + (j - 1)]).collapse('show');
$('#klassifikation-' + klass_id).css("font-weight", "Bold");
});
}
else {
$('#klassifikation-' + klass_id).css("font-weight", "Bold");
}
j++;
}