在這里,我從文本檔案中讀取資料,其中行由字串分隔OUT_,列由\n
我正在過濾資料并丟棄<9col 長度的任何陣列,并且%在 col 6 處沒有
然后我想按 col 字母順序排序0,并在 col 中對所有同名的陣列進行分組0
回傳一個三元組
async function fetchText() {
let response = await fetch('http://127.0.0.1:8080//data.txt');
let dataOut = await response.text();
var n = dataOut.split("OUT_");
var lastTester = "";
var new_array = [[[]]];
for (var x in n) {
var m = n[x].split("\n");
var temp_array = [[]];
if (m.length > 9)
if (m[6].indexOf('%') > -1) {
temp_array.push(m);
if (lastTester !== m[0]) {
new_array.push(temp_array);
temp_array = [[]];
document.write("Appended ");
}
lastTester = m[0];
}
}
return new_array;
}
tester_array = fetchText();
document.write(tester_array[1][1][0]);
document.write(tester_array.length());
但是,我沒有得到任何輸出,似乎tester_array是空的
document.write(tester_array[1][1][0]);
document.write(tester_array.length());
它寫入Appended 網頁,因此不是資料輸入或文本檔案問題,
我在創建和追加陣列時做錯了什么?代碼中需要改變什么?
該data.txt檔案如下所示(經過編輯以洗掉機密資訊):
OUT_FusingPower BI
Manufacturing Central
|
Pages
MFG Yield Summary
%100
%100
%100
MFG Yield Trend
MFG Error Details
Yield by Line/Tester
EC FR by Line/Tester
OLR Report
Tester Comparision
Yield by Part Number
Test Time
OUT_Tester by Station
Error Code Details
Yield by Site
About
File
%100
%100
%100
%100
OUT_Analytics - Errorcode Failure Rate by Line/Tester
Site
All
Project
Rumba
%100
%100
%100
All
Station
All
Current Week?
Multiple selections
Shift
uj5u.com熱心網友回復:
您的功能是異步的,您無需等待解決承諾。因此,在訪問 tester_array 時,promise 尚未完成。
fetchText().then(result => {
console.log(result[1][1][0])
console.log(result.length)
})
您可以使用.then,或者您需要使用 async/await 方法。
async function fetchText() {
let dataOut =
`OUT_FusingPower BI
Manufacturing Central
|
Pages
MFG Yield Summary
0
0
0
MFG Yield Trend
MFG Error Details
Yield by Line/Tester
EC FR by Line/Tester
OLR Report
Tester Comparision
Yield by Part Number
Test Time
OUT_Tester by Station
Error Code Details
Yield by Site
About
File
0
0
0
0
OUT_Analytics - Errorcode Failure Rate by Line/Tester
Site
All
Project
Rumba
0
0
0
All
Station
All
Current Week?
Multiple selections
Shift`;
var n = dataOut.split("OUT_");
var lastTester = "";
var new_array = [[[]]];
for (var x in n) {
var m = n[x].split("\n");
var temp_array = [[]];
if (m.length > 9)
if (m[6].indexOf('%') > -1) {
temp_array.push(m);
if (lastTester !== m[0]) {
new_array.push(temp_array);
temp_array = [[]];
console.log("Appended");
}
lastTester = m[0];
}
}
return new_array;
}
fetchText().then(result => {
console.log(result[1][1][0]);
console.log(result.length);
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/518625.html
