Asynchronous 带有进度事件的Queue.js

Asynchronous 带有进度事件的Queue.js,asynchronous,queue,d3.js,Asynchronous,Queue,D3.js,我想加载多个文件以在D3.js中使用。js似乎是一个很好的工具。由于d3.js在v3中支持更高级的XHR功能,因此我想使用Queue.js加载多个文件,并显示加载进度,并在出错时中止加载所有文件 以下是检查进度的方式以及如何使用Queue.js: 我不知道如何组合这些代码 这就是我到目前为止所拥有的。 我认为Queue.js上最好有一个进度事件处理程序,但我不知道如何实现它 示例代码: queue() .defer(d3.json, "file1.json") // https://api

我想加载多个文件以在D3.js中使用。js似乎是一个很好的工具。由于d3.js在v3中支持更高级的XHR功能,因此我想使用Queue.js加载多个文件,并显示加载进度,并在出错时中止加载所有文件

以下是检查进度的方式以及如何使用Queue.js:

我不知道如何组合这些代码

这就是我到目前为止所拥有的。

我认为Queue.js上最好有一个进度事件处理程序,但我不知道如何实现它

示例代码:

queue()
  .defer(d3.json, "file1.json") // https://api.github.com/repos/mbostock/d3")
  .defer(d3.json, "file2.json")
  .progress(function() { console.log(d3.event.loaded/d3.event.total; }) // or use argument?
  .error(function(error) { this.abort(); console.log(error); })
  .await(function(data) { console.log(data); });
queue().defer(d3.json("file1.json")
                 .on("progress", function({console.log(d3.event.loaded);})                                               
                 .get, /*First argument*/ "error")
       .await(function (error, file1_data) {console.log(file1_data);});

queue.js中queue()返回的对象没有“progress”和“error”方法。以下是指向源代码的链接:

由于queue.js接受一个xhr对象并使用“apply”来执行该函数,下面的解决方法对我来说很有效。它涉及使用xhr对象的get()方法来执行函数

示例代码:

queue()
  .defer(d3.json, "file1.json") // https://api.github.com/repos/mbostock/d3")
  .defer(d3.json, "file2.json")
  .progress(function() { console.log(d3.event.loaded/d3.event.total; }) // or use argument?
  .error(function(error) { this.abort(); console.log(error); })
  .await(function(data) { console.log(data); });
queue().defer(d3.json("file1.json")
                 .on("progress", function({console.log(d3.event.loaded);})                                               
                 .get, /*First argument*/ "error")
       .await(function (error, file1_data) {console.log(file1_data);});

希望这有帮助。

当您尝试使用同一队列导入多个JSON文件时,这是否有效?