![](/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.