如何获取返回值的内容

how do i get the content of a returning value?

本文关键字:返回值 获取 何获取      更新时间:2023-09-26

我在Phonegap应用程序上工作了一段时间,我正在使用这个插件将文件从服务器下载到设备上的Documents/forder:

https://github.com/torrmal/cordova-simplefilemanagement

我测试了这个插件,它工作正常。它下载文件并读取文件。

// READ A FILE
c.read_file('data/','content.json',Log('file contents: '),Log('something went wrong'));

painlessfs.js做了一些事情:

this.read_file = function(dir, filename, success, fail){
    // console.log(dir);
    fail = (typeof fail == 'undefined')? Log('FileManager','read file fail'): fail;
    this.load_file(
        dir,
        filename,
        function(fileEntry){
            fileEntry.file(
                function(file){
                    var reader = new FileReader();
                    reader.onloadend = function(evt) {
                        success(evt.target.result);
                    };
                    reader.readAsText(file);
                }, 
                fail
            );
        },
        fail
    );
};

我取回这个日志:

Oct 22 15:12:00 Iphone-van-patrick A12 VEG[10479] <Warning>:  file contents: :
Oct 22 15:12:00 Iphone-van-patrick A12 VEG[10479] <Warning>:        {"data":[{"Id":"1","C_Code":"Frontpage_Title","C_output":"A12-VEG"},{"Id":"2","C_Code":"Frontpage_Welkom","C_output":"Welkom A12-VEG"},{"Id":"3","C_Code":"Frontpage_intro","C_output":"hiiii"}]}

正如周所见,它运行良好。。。但我想要的是,我需要将"文件内容"绑定到例如"FileContent"

我试过的是:

// READ A FILE
c.read_file('data/','content.json',FileContent(evt.target.result),Log('something went wrong'));
Function FileContent (Content){
console.log(Content);
}

我想返回文件的内容。

有人能看看并帮我做这个吗?

编辑:所以我发现:"evt.target.result"保存文件的内容,并将其返回为"success"。但是我如何从"成功"中获得这些数据呢??

你喜欢这样:

c.read_file('data/','content.json', function(r) { console.log(r) }, Log('something went wrong'));