javascript - queue.js 从本地变量而不是外部文件传递数据

标签 javascript json d3.js dc.js queue.js

我想使用 json 变量传递数据。 在下面的示例中,json 是从外部 JSON 文件获取的。 任何人都可以帮助我如何从局部变量传递数据,因为我是 dc.js 的新手

queue()
    .defer(d3.json, "sampledata.json") // sampledata.json  is an external json file
    .await(makeGraphs);

function makeGraphs() {
   //function which proceses the data
}

我试过了

var sampledata = [ ....];
queue().defer(d3.json, "sampledata.json") // sampledata.json  is an external json file
        .await(makeGraphs);

    function makeGraphs() {
       //function which proceses the data
    }

但没有成功。

最佳答案

如果您有一个局部变量,那么使用异步调用来传递它是没有意义的。只需立即将其作为参数传递即可:

var sampleData = [...];//this is your data

makeGraphs(sampleData);//call your function using it as an argument

然后:

function makeGraphs(data){//this is the parameter
     //use 'data' here
}

关于javascript - queue.js 从本地变量而不是外部文件传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40235162/

相关文章:

ruby-on-rails - 将 JSON 从 API 端点保存到 Ruby on Rails 应用程序中的数据库

javascript - selenium webdriver 不适用于 jasmine

javascript - 调用没有元素的 javascript 函数

c# - 网页与COM口对接控制页面

javascript - 脚本错误 - requireJS

javascript - 如何在 csv 对象数据中插入 header 以使用 d3.js 进行管理

node.js - Node.js 中 d3 和 mongo 之间的冲突

javascript - 使用正则表达式创建一个新数组以查找以 A 到 J 开头的元素

java - 错误 400 : Bad Request involving Timestamp within JSON object

json - Unmarshal() 正在返回空结构