2

我正在使用Papaparse并且我正在尝试解析一个 CSV 文件,该文件保存在www.

它适用于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
    });
};

提前致谢!

4

1 回答 1

2

这里同样的问题。

我在 ios 上的 pouchdb load 中发现了这个问题。看起来

...由于某种原因,即使从文件中加载了数据,iOS 也会返回 0 作为 xhr 请求的状态

所以我改变了 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中添加了相同的答案。可能会包含这个补丁。

于 2016-07-06T08:03:57.440 回答