![](/img/trans.png)
[英]React Native: How do I display a variable in a Text element once an async function has returned it?
[英]How do I display text in a .txt file with an async function with jsonp?
我正在尝试显示来自 API 的文本,这是一个 .txt 文件。 它可能与
async function load_url() {
let response = await fetch("<txt file>");
但我不知道如何处理 rest。
另外在线检索某行的代码是什么? 就像,我将如何在一个 .txt 文件中仅检索“鱼”?
Cat
Fish
Giraffe
Bison
您应该使用 json 文件,Homewhere,我们需要知道您的后端使用哪种语言
编辑:
如果 API 向您返回一个文本文件,您可以这样做:
var lines = this.response.split('\n');
for(var line = 0; line < lines.length; line++){
console.log(lines[line]);
//If you want to show a specific line, just give the correct index
}
编辑:
您只是没有任何回应您的要求
更新:这是我的新代码:
async function load_url() {
let response = await fetch("https://patrickmcneill.com/itp/urls.txt");
var lines = this.response.split('\n');
for(var line = 0; line < lines.length; line++){
console.log(lines[line]);
}
}
load_url();
但我返回"Uncaught (in promise) TypeError: Cannot read property 'split' of undefined at load_url" 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.