I have the following code
$.when(tableInsert("index.php/get/sync/riesgos", insert_riesgo, evalua.webdb.db, callback)).then(function(){
update_records("riesgos");
$.when(tableInsert("index.php/get/sync/estancias", insert_estancia, evalua.webdb.db, callback)).then(function(){
update_records("estancias");
$.when(tableInsert("index.php/get/sync/riesgosestancias", insert_riesgoestancia, evalua.webdb.db, callback)).then(function(){
update_records("riesgosestancias");
});
});
});
I am trying to find how to integrate it inside of a for loop or a $.each loop, so that it waits for the promise to be done before the next iteration. At first it looks like three calls would be easier to be nested, but this is only a piece of code, the nested calls count 15 now!
Well, you need an array with the data first, for example:
and then you can chain the calls using
.pipe[docs]:There is no need for
$.whenin your example.