js从本地变量传递数据,而不是从外部文件

queue.js pass data from local variable not from external file

本文关键字:文件 从外部 数据 变量 js      更新时间:2023-09-26

我想使用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
}

i tried this

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
}