function genTask(elem){
elem.each(function(){
$this=$(this).parent('.cntTasks');
var pattern=/taskId-(.*)$/
var idTask=$this.attr('id').match(pattern);
var data='id_task='+idTask[1];
if(typeof jsVar2 !='undefined') data+=jsVar2;
$.ajax({
type: "POST",
url: domain+"/view_tasks/gen_tasks/",
dataType: 'html',
data: data,
success: function(dt){
$this.find('.contChildTasks').html(dt);
childs=$this.children('.taskDesc').find('.has_child');
if(childs.length!=0)
genTask(childs);
}
}
});
$this.find('.taskDesc').show();
});
}
if(typeof jsVar2 !='undefined') genTask($('.cntTasks .has_child'));
});
jak to możliwe, aby $.each
poczekać aż akcja $.ajax
zostaną zakończone, a następnie kontynuować pętli, nie mogę dostać $ to zmienna, ponieważ ma ostatnią wartość , przepraszam za mój angielski, DZIĘKUJĘ !!!!
Być może mógłbyś ustawić atrybut 'async' $ .ajax na 'false'? Zobacz: http://api.jquery.com/jQuery.ajax/ – Armin