• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

javascript - 在 Cordova iOS 中使用 Papaparse 解析本地 CSV 文件

[复制链接]
菜鸟教程小白 发表于 2022-12-12 21:08:38 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在使用 Papaparse 并尝试解析保存在 www 内的文件夹中的 CSV 文件。

它适用于 androidbrowser 平台。

但是,当涉及到 iOS 时,它会返回错误回调。

当我输出错误时,它返回 undefined

我还检查了iOS的文件路径是否正确,文件确实存在。

我已经尝试将文件路径设置为 "folder/myfile.csv" 但由于它导致错误,我尝试使用文件插件获取其完整路径。

其他人遇到过同样的问题并有解决方法吗?

这是我的代码。

var getOldData = function() {
    var dir = "folder/myfile.csv",
        file = null;

    file = (isiOS) ? cordova.file.applicationDirectory + "www/" + dir : dir;

    Papa.parse(file, {
        download: true,
        error: function(err, file) {
            console.log(">>>> PAPA PARSE ERROR");
            console.log(">>>>" + err); // this returns undefined
            console.log(">>>>" + file); // this returns undefined as well
        },
        complete: function(results) {
            console.log(">>>> PAPA RESULTS");
            console.log(results);
        },
        header: true,
        dynamicTyping: true
    });
};

提前致谢!



Best Answer-推荐答案


同样的问题。

我找到了 this issue在 ios 上的 pouchdb 中加载。看来

... for some reason, iOS is returning 0 as the status for the xhr request even when there is data loaded from file

所以我在 papaparse _chunkLoaded 函数中改了,这一行

if (xhr.status < 200 || xhr.status >= 400)

这个:

if (!((xhr.status >= 200 && xhr.status < 300) || (xhr.status==0 && xhr.responseText.length>0)))

现在它可以工作了。

我在相应的 github issue 中添加了相同的答案. 可能会包含这个补丁。

关于javascript - 在 Cordova iOS 中使用 Papaparse 解析本地 CSV 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38194078/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap