How to ensure jQuery $.each is finished before continuing
I am working on a jQuery plugin with an add_record method (see below). If
you look at the function definition, there are two $.each loops that
append values to plugin.payload.
Right now, everything works fine. However, what if records or options is
really big? Do I need to be concerned about the $.each()'s not finishing
before the transmit call is issued?
If so, what is the best way to address the issue?
plugin.add_record = function(records, options, callback) {
if ( typeof(options) == "function") {
callback = options;
options = undefined;
}
if(options) {
$.each(options, function(index, value) {
plugin.payload.append($(value));
});
}
$.each(records, function(index, value) {
plugin.payload.append($(value));
});
transmit('API_AddRecord', plugin.payload, 'db', function(data) {
return typeof(callback) == "function" ? callback(data) : data;
});
}
No comments:
Post a Comment