【问题标题】:How can I use Ionic 3 to get the content of a text file as a string?如何使用 Ionic 3 将文本文件的内容作为字符串获取?
【发布时间】:2017-12-02 21:48:29
【问题描述】:

我试过这个:

this.item = this.params.get('filename');
console.log("[INFO] Opening File: >" + this.item + "<");
this.textboxContent = this.file.readAsText(this.file.dataDirectory, this.item);
console.log("[INFO] Content of textboxContent: >" + this.textboxContent + "<");

但是我进入了 logcat:

[INFO:CONSOLE(56865)] "[INFO] textboxContent 的内容:>[object 承诺]

this.item 是:

[INFO:CONSOLE(56863)] "[INFO] 打开文件:>SomeFile.txt

【问题讨论】:

    标签: android typescript ionic-framework ionic3


    【解决方案1】:

    这是因为 readAsText 返回一个承诺。你应该这样做

    this.file.readAsText(this.file.dataDirectory, this.item).then((content)=>  
    {
      this.textboxContent = content;
    })
    

    【讨论】:

    • 效果很好!非常感谢!
    • 不客气。你能接受这个答案吗?谢谢。
    • @MrFlyingToasterman 很高兴听到您解决了这个问题!请将此答案标记为已接受的答案,以便我们关闭问题:)
    • 很抱歉,我还在开会,正在午休。当然:)
    猜你喜欢
    • 2015-08-08
    • 2014-08-09
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    • 2013-06-18
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多