1
我在本地机器上有一个文件,我想阅读。我正在使用create-react-app
来创建我的react
应用程序。从反应中逐行读取本地.csv文件
const csv =require('/path/to/csv')
的文件基本上是一个.csv
这样的:
IBM, .025
GE, .33
etc
我想读这个文件,逐行。我无法弄清楚如何去做。该文件需要之前什么都在,看起来像这样
import React from 'react';
import ReactDOM from 'react-dom';
const csv =require('/path/to/csv');
const App = React.createClass({
// I would like to have the file read before stuff in here gets called
});
const appRoot = document.createElement('div');
document.body.appendChild(appRoot);
ReactDOM.render(<App />, appRoot);
如果您使用的是webpack,这个加载器https://github.com/theplatapi/csv-loader可能会帮助 – juliobetta
C不要让readTextFile工作。我可以在浏览器中输入路径,并查看文本文件的内容。但在编程上我无法让它工作。使用Chrome。 – Ivan
我得到file:/// D:/Documents/js/table-example1/src/optimal.csv。协议方案仅支持跨源请求:http,data,chrome,chrome-extension,https。 – Ivan