javascript - 使用这些 [input] 和 [output] 函数有什么意义
问题描述
我在 GitHub 上的 react-native excel 导出演示中找到了这个,我不明白为什么这两个函数是必要input
的output
,为什么不直接传递wbout
给writeFile
,这是一些函数式编程类型的东西吗?
const input = res => res;
const output = str => str;
const exportFile =()=> {
//...some code
writeFile(file, output(wbout), 'ascii').then((res) =>{
console.log("exportFile success", "Exported to " + file);
}).catch((err) => {
console.log("exportFile Error", "Error " + err.message);
});
};
const importFile=()=> {
readFile(DDP + "sheetjs.xlsx", 'ascii').then((res) => {
/* parse file */
const wb = XLSX.read(input(res), {type:'binary'});
//...rest of coe
})
}
解决方案
查看注释块中的标题:
// react-native-fetch-blob
/*
import RNFetchBlob from 'react-native-fetch-blob';
const { writeFile, readFile, dirs:{ DocumentDir } } = RNFetchBlob.fs;
const DDP = DocumentDir + "/";
const input = res => res.map(x => String.fromCharCode(x)).join("");
const output = str => str.split("").map(x => x.charCodeAt(0));
*/
在您的情况下input
或output
没有必要,但是当您删除react-native-fetch-blob
.
此处的功能是为两个演示提供一个代码。
推荐阅读
- xml - 使用 XSLT 显示所有元素的元素 repititions 之间的 Subtotolas
- php - Laravel 7浏览器不下载文件
- arrays - 将特定值移动到随机填充数组的末尾
- asp.net-core - 为托管的 blazor 实现进度条
- c++ - 字符串文字中换行符的换行计数器 [更新]
- reactjs - React/redux combineReducers 问题
- youtube-api - youtube iframe api没有触发事件
- javascript - nginx网站启动缓慢
- laravel - 无法访问 Laravel Homestead。如何更改 SSH 密钥?
- docker - 使用 .NET 客户端在 ElasticSearch 上定义索引模板