admin管理员组文章数量:1435796
My webpage lets the user plot multiple timeseries on a chart and I am using queue.js to go and asynchronously get this data, like so:
queue()
.defer(d3.json, "api/TransactionCost/?marketCode=" + marketCode1)
.defer(d3.json, "api/TransactionCost/?marketCode=" + marketCode2)
.defer(d3.json, "api/TransactionCost/?marketCode=" + marketCode3)
.await(onDataLoaded);
function onDataLoaded(error, json1, json2, json3) {
// plot the 3 timeseries
}
I want the user to be able to request extra lines, if they wish, which will mean that I need to do extra 'defer' calls. I'd like to know how to dynamically append extra 'defer' calls (if it's possible) and also how to create the 'onDataLoaded' function so that it can handle a variable amount of parameters.
My webpage lets the user plot multiple timeseries on a chart and I am using queue.js to go and asynchronously get this data, like so:
queue()
.defer(d3.json, "api/TransactionCost/?marketCode=" + marketCode1)
.defer(d3.json, "api/TransactionCost/?marketCode=" + marketCode2)
.defer(d3.json, "api/TransactionCost/?marketCode=" + marketCode3)
.await(onDataLoaded);
function onDataLoaded(error, json1, json2, json3) {
// plot the 3 timeseries
}
I want the user to be able to request extra lines, if they wish, which will mean that I need to do extra 'defer' calls. I'd like to know how to dynamically append extra 'defer' calls (if it's possible) and also how to create the 'onDataLoaded' function so that it can handle a variable amount of parameters.
Share Improve this question asked Feb 10, 2014 at 20:27 ninjaPixelninjaPixel 6,3924 gold badges38 silver badges50 bronze badges1 Answer
Reset to default 10I'd like to know how to dynamically append extra 'defer' calls (if it's possible)
Use a variable for the queue, and dynamically append defer
calls to it:
var q = queue();
for (/* each file */)
q = q.defer(d3.json, filename);
q.await(onDataLoaded);
how to create the 'onDataLoaded' function so that it can handle a variable amount of parameters.
You can use the arguments
object to access a variadic amount of parameters. In your case, it would look like
function onDataLoaded(error) {
if (!error) {
// Either simply loop them:
for (var i=1; i<arguments.length; i++)
… arguments[i] …
// or slice them into an array:
var jsons = Array.prototype.slice.call(arguments, 1);
…
} else { … }
}
本文标签: javascriptDynamically change the number of 39defer39 calls in queuejsStack Overflow
版权声明:本文标题:javascript - Dynamically change the number of 'defer' calls in queue.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745643288a2667985.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论