Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用d3获取模块加载多个文件_Javascript_D3.js_Riot.js - Fatal编程技术网

Javascript 使用d3获取模块加载多个文件

Javascript 使用d3获取模块加载多个文件,javascript,d3.js,riot.js,Javascript,D3.js,Riot.js,我尝试从两个不同的来源加载数据。加载数据后,我想在riot标记文件中使用它。但是我不知道如何加载第二个文件,因为我不太理解异步调用 我必须在代码中修改什么才能获得数据?现在,第二个数据对象尚未定义。这是我的密码: import { csv, json } from 'd3-fetch' csv('/data/stations.csv', function (stations) { json('data/svg_data.json', function (svg) { return s

我尝试从两个不同的来源加载数据。加载数据后,我想在riot标记文件中使用它。但是我不知道如何加载第二个文件,因为我不太理解异步调用

我必须在代码中修改什么才能获得数据?现在,第二个数据对象尚未定义。这是我的密码:

import { csv, json } from 'd3-fetch'
csv('/data/stations.csv', function (stations) {
  json('data/svg_data.json', function (svg) {
    return svg
  })
  stations.position_x = +stations.position_x
  stations.position_y = +stations.position_y
  stations.animation_time = +stations.animation_time
  stations.text_x = +stations.text_x
  stations.text_y = +stations.text_y
    return stations
  }).then(function (stations, svg) {
   mount('metro-app', {
     stations: stations,
     svg_data: svg
  })
})
模块使用,因此,对于通过模块的便利方法之一发出的每个请求,将返回一个。若要一次加载多个文件,您可以使用,它将返回一个承诺,一旦提供给调用的所有承诺都得到解决,该承诺就会得到解决

import { csv, json } from 'd3-fetch'

Promise.all([
  csv('/data/stations.csv'),
  json('data/svg_data.json')
])
.then(([stations, svg]) =>  {
  // Do your stuff. Content of both files is now available in stations and svg
});
这里提供了
d3.csv
d3.json
来从两个文件中获取内容。一旦两个请求都已完成,即两个承诺都已解决,每个文件的内容将提供给单个承诺的方法调用。此时,您可以访问数据并执行其余代码