Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.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 通过csv传递api数据_Javascript_Html_Json_Reactjs_Redux - Fatal编程技术网

Javascript 通过csv传递api数据

Javascript 通过csv传递api数据,javascript,html,json,reactjs,redux,Javascript,Html,Json,Reactjs,Redux,我正在使用react csv生成excel文件 我下载了一个示例数据,但要下载JSON数据,我不知道如何将JSON文件从RecipeViewCardList文件传递到tab demo.js文件 您能告诉我如何传递下面提供我的代码更改和沙箱的数据吗 这将帮助我了解更多,并在将来自己解决问题。 选项卡demo.js <div> 230 sports | test Export Excel | Export PDF <CSVLink data={csvData}&g

我正在使用react csv生成excel文件

我下载了一个示例数据,但要下载JSON数据,我不知道如何将JSON文件从
RecipeViewCardList
文件传递到
tab demo.js
文件

您能告诉我如何传递下面提供我的代码更改和沙箱的数据吗

这将帮助我了解更多,并在将来自己解决问题。

选项卡demo.js

<div>
    230 sports | test Export Excel | Export PDF
    <CSVLink data={csvData}>Download me</CSVLink>;
    <CSVDownload data={csvData} target="_blank" />;
</div>
 getCommentsData() {
    let comments = [];
    fetch("https://jsonplaceholder.typicode.com/comments")
      .then(response => response.json())
      .then(json => {
        comments = json;
        // comments = comments.slice(0,3);
        this.setState({ comments: comments });
        this.setState({ activeComments: comments.slice(0, 10) });
        //console.log(comments);
    return this.state.comments.length > 0 ? (
      <div>
        <div>
          230 sports | test Export Excel | Export PDF
          <CSVLink data={this.state.csv}>Download me</CSVLink>;
          <CSVDownload data={this.state.csv} target="_blank" />;
        </div>
        {listView}
        <br />
        ...
使用解决方案对沙盒(基于您的)进行编码:

在您的代码中,“React Styleing”非常糟糕,但根据以下问题:

div部分从选项卡demo.js移动到RecipeViewCardList.js

<div>
    230 sports | test Export Excel | Export PDF
    <CSVLink data={csvData}>Download me</CSVLink>;
    <CSVDownload data={csvData} target="_blank" />;
</div>
 getCommentsData() {
    let comments = [];
    fetch("https://jsonplaceholder.typicode.com/comments")
      .then(response => response.json())
      .then(json => {
        comments = json;
        // comments = comments.slice(0,3);
        this.setState({ comments: comments });
        this.setState({ activeComments: comments.slice(0, 10) });
        //console.log(comments);
    return this.state.comments.length > 0 ? (
      <div>
        <div>
          230 sports | test Export Excel | Export PDF
          <CSVLink data={this.state.csv}>Download me</CSVLink>;
          <CSVDownload data={this.state.csv} target="_blank" />;
        </div>
        {listView}
        <br />
        ...
当然,csv也会添加到州中

我希望这些将是有益的