var modulesDemo = ['module1', 'module2'];
var moduleHtml='', pdfContent='';
$。每个(modulesDemo,函数(指数,模块){使用回调函数,然后循环不会等待功能齐全
if(typeof window[module] === 'function'){
window[module](function(content){
moduleHtml +=content;
if(modulesDemo.length==index+1){
pdfContent += '<table>';
pdfContent += moduleHtml;
pdfContent += '</table>';
console.log(pdfContent);
}
});
}
});
function module1(callback){
var content='';
var canvas = $("#demoCanvas")[0];
var img = canvas.toDataURL("image/png");
content += '<tr>';
content += '<td>';
content += '<img style="width:100%;height:100%;margin-top:20px !important" src="'+img+'" />';
content += '</td>';
content += '</tr>';
callback(content);
}
function module2(callback){
function module2(callback){
var img;
var content;
html2canvas($("#demoCanvas1"), {
onrendered: function(canvas) {
img = canvas.toDataURL("image/png");
content += '<tr>';
content += '<td>';
content += '<img style="width:100%;height:100%;margin-top:20px !important" src="'+img+'" />';
content += '<td>';
content += '</tr>';
//alert(2);
callback(content);
}
});
}
}
<!-- language: lang-html -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id='demoCanvas'></canvas>
<!-- end snippet -->
,当我使用$。每次回调然后循环不工作synchronous.Iterate不会等待功能complete.Can任何人帮助我。
将尽一切努力理解
谢谢!
在这里每个$,你已经注册同步回调,但以什么顺序,他们将被称为不保证。 –
那么问题的症状是什么,moduleHtml的顺序是错误的? – James