現(xiàn)在想用Promise讓所有圖片加載完之后執(zhí)行其他邏輯看了很多資料會(huì)簡(jiǎn)單使用Promise了,但是在循環(huán)里就蒙了。。Promise.all()的參數(shù)該怎么弄呢?$.each(data, function (i, n) { //insert Name wall.insert(n.id, n.nickname, 'name'); //Photo and Avatar load wall.loadImg(n.photo, function () { wall.loadImg(n.avatar, function () { wall.insert(n.id, n.avatar, 'avatar'); wall.insert(n.id, n.photo, 'photo'); wallData.showKey.push(n.id); }); });});wall.loadImg = function (url, cb, er) { new Promise((resolve, reject) => { var img = new Image(); img.src = url; if(img.complete){ cb() resolve() }else { img.onload = function(){ resolve() }; img.onerror = er; } }); };
Promise的用法問(wèn)題
呼啦一陣風(fēng)
2018-08-07 14:14:43