배열을 통해 루핑 할 때 지연된 모든 fileRead가 해결되면 'done'이 기록됩니다.When and Deferred
$.when.apply(null, $.each(files, function(index, file){
return self.fileRead.read(file).done(function(fileB64){
self.fileShow(file, fileB64, fileTemplate);
});
})).done(function() {
console.log('done');
})
문제는 fileShow 메서드가 반환 된 후에 만 기록하면됩니다.
이 fileShow 메서드는 또한 지연을 구현해야합니까? 아니면 그냥 돌아올 수 있습니까?
어떻게하면 모든 fileShow 메소드가 실행 된 후에 console.log ('done')가 실행되도록 루프를 수정할 수 있습니까?
'$ .each' 대신'$ .map'을 사용하면'Deferred' 객체를 반환 할 수 있습니다. '$ .each'는 첫번째 인자를 반환합니다. – Barmar
@Barmar example? – user3729576