javascript - React:将数据从地图函数下载到文件中
问题描述
如何将地图函数中的数据下载到文本文件中?我有以下内容:
const downloadTxtFile = () => {
const element = document.createElement('a');
const file = new Blob([document.getElementById('result').innerHTML], { type: 'text/plain' });
element.href = URL.createObjectURL(file);
element.download = 'Capture_Download.txt';
document.body.appendChild(element); // Required for this to work in FireFox
element.click();
};
哪个有效并且确实下载了带有数据的文件但我只得到文件中的第一个结果。
{data.map((result, i) => (
<div className='py-1'>
<span className='font-mono' id='result'>
<pre>
<span className='text-xs text-gray-400 font-mono'>Capture {i} : </span>
<code >{result}</code>
</pre>
</span>
<br />
</div>
))}
result
类似于:
捕获 0:0.15
捕获 1:1.68
捕获 2:0.26
捕捉 3:无底价
但我只是进入<pre><span class="text-xs text-gray-400 font-mono">Capture 0 : </span><code>0.15</code></pre>
文件。我怎样才能得到文件中的最终结果?
解决方案
推荐阅读
- amazon-web-services - S3 禁用列表并获得 404 而不是 403
- python - 如何修复 ModuleNotFoundError:在 Python 中导入嵌套时没有名为“nest”的模块?
- r - 使用 glm2() 使用泊松回归对速率数据进行建模
- git - 如何将私人仓库转移到 vm 中的 jupyter 实验室?
- python-3.x - 在 sqlite3 的 WHERE 子句中使用用户定义的函数
- function - 在powershell中调用函数时使用与参数和存储相同的变量
- java - 阻止对 Jetty 服务器的请求
- c++11 - 问题
并使用基本名称 - html - 当导航按字体自动调整大小时,如何使图像与导航一样大?
- sql - 使用继承时违反主键唯一性