Queue.js to preload images is waiting forever? (Callback)

自古美人都是妖i 提交于 2019-12-01 21:40:37
explunit

Here is what queue.js is expecting from the callbacks:

The callbacks follow the Node.js convention where the first argument is an optional error object and the second argument is the result of the task.

Thus a simple version of your code might look like this:

var loadImage = function(src, cb) {
    var img = new Image();
    img.src = src;
    img.onload  = function(){ cb(null, img); };
    img.onerror = function(){ cb('IMAGE ERROR', null); };
};

queue()
    .defer(d3.json, "data/flare.json")
    .defer(d3.csv, "data/test.csv")
    .defer(loadImage, "img/test.png")
    .await( function(error, jsondata, csvdata, imagedata) {
        if (error) { console.log('error', error); } 
        else { console.log('success', jsondata, csvdata, imagedata) }
    });

I'm not sure what (if anything) you wanted to return about the image, but in the above example cb(null, img) I'm returning the whole object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!