javascript - When and Deferred -
i'm looping through array, when fileread deferred resolved, 'done' logged.
$.when.apply(null, $.each(files, function(index, file){ homecoming self.fileread.read(file).done(function(fileb64){ self.fileshow(file, fileb64, filetemplate); }); })).done(function() { console.log('done'); }) the problem is, wish done logged 1 time fileshow method has returned.
does fileshow method need implement deferred. or can return?
how can modify loop console.log('done') ran 1 time fileshow methods have been executed?
use $.map instead of $.each. returns array of deferred objects returned iteration function, , these can passed $.when.
$.when.apply(null, $.map(function(index, file) { homecoming self.fileread.read(file).done(function(fileb64) { self.fileshow(file, fileb64, filetemplate); }); })).done(function() { console.log('done'); }); javascript jquery each .when
No comments:
Post a Comment