In the end, I used something like Drasill, but it was a bit confusing. I guess this will ruin if you called him twice, without waiting for the first time, because of how the events work.
var save_multiple_stores = function(stores, success, fail) { if (stores.length === 0) { if (success) { success(); } } else { var store = stores.pop(); var listeners = {} var unbind_listeners = function() { for (var evt in listeners) { store.un(evt, listeners[evt]); } } var onsuccess = function() { unbind_listeners(); save_multiple_stores(stores, success, fail); } var onfail = function() { unbind_listeners(); if (fail) { fail(); } } store.on('save', onsuccess); listeners.save = onsuccess; store.on('exception', onfail); listeners.exception = onfail; var num_records = store.save();
source share