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