我正在尝试对正在使用FileReader()读取文件时上传的csv文件进行验证
整个逻辑在调试模式下工作完美,但在发行版中则无效。
var reader = new FileReader();
reader.readAsBinaryString(file);
var allTextLines;
new Promise(function(resolve, reject) {
allTextLines = reader.result.split(/\r/);
setTimeout(() => resolve(allTextLines), 1000); // (*)
// return allTextLines;
}).then(function(result) { // (**)
alert(result); // 1
var headers = result[0].split(',');
return headers;
//return result * 2;
}).then(function(headers) { // (***)
alert(headers); // 2
var massUploadCount = 0;
for (var i = 1; i < allTextLines.length - 1; i++) {
var data = allTextLines[i].split(',');
if (data.length == headers.length) {
var tarr = [];
for (var j = 0; j < headers.length; j++) {
if (headers[j].toUpperCase().trim() === 'ITEM NUMBER') {
var itemNum_regex = /^[\d]{0,10}$/;
if (!(itemNum_regex.test(data[j]))) {
console.log("hello from polo");
massUploadCount++;
com.ws.mdmui.common.showDialog("Error", 'Please enter correct value for ' + headers[j] + ' in row ' + i);
return;
} else {
tarr.push(data[j]);
}
}
}
}
}
return massUploadCount;
});