0
var checkduplicates = new Array();
drawOne(i);
//console.log(checkduplicates)
function drawOne(i)
{
//randomly select one photo
var picinfo = photos[Math.floor(Math.random()*photos.length)];
//check duplicates pic, if duplicates exist, get another one
while(checkduplicates.indexOf(picinfo)!=-1||picinfo.title.length>10)
{
picinfo = photos[Math.floor(Math.random()*photos.length)];
}
checkduplicates.push(picinfo);
var ctx = document.getElementsByClassName("canvas")[i].getContext('2d');
var img = new Image();
//get the pic URL
img.src = "http://farm" + picinfo.farm + ".static.flickr.com/"
+ picinfo.server + "/" + picinfo.id + "_" + picinfo.secret + "_m.jpg";
img.onload = function()
{
// Draw pieces
ctx.drawImage(img,0,0,132,150);
ctx.drawImage(frame,0,0,133,152);
if(picinfo.title=="")
$("#"+i).append("Untitled");
else
$("#"+i).append(picinfo.title);
i++;
if (i != canvaslength)
{
drawOne(i);
}
}
我在这里做的是我动态生成图片来填充16画布,有人说我使用异步递归,我甚至没有注意到。我试图使用循环,而不是递归,但不知何故结束它得到异常,我不知道如何解决。所以我坚持递归。但是,我的问题是,我如何检测递归结束像注释行显示数组中只有一个项目。检测异步递归的结束
//console.log(checkduplicates)
和我得到的解释是,据我所知,该评论的console.log是一堆drawOne函数完成递归的前执行,但我想要的是,我想的全部16个图像是满载然后选择它们以便我可以对它们做些什么。因此,问题是我如何检测递归的结束。谢谢。欢迎您忽略我的大部分代码,并查看递归部分。