无法访问nodejs代码中的值
Not able to access value in nodejs code
我的节点 js 函数中有以下代码。即使 IF 条件为真,我也没有为字符串 Response 变量更新值。
var fs = require('fs'),
byline = require('byline');
var stream = fs.createReadStream('Solutionbank.csv');
var stringResponse = "We found a similar issue. ";
stream = byline.createStream(stream);
stream.on('data', function(line) {
var csvLine = line.toString('utf8');
csvLine = csvLine.toLowerCase().trim();
var msgText = subject.toLowerCase().trim();
//console.log("email block",msgText);
if(csvLine.indexOf(msgText) > -1) {
var arr = line.toString('utf8').split(",");
stringResponse = stringResponse + "Issue ID"+arr[0]+",Subject : "+arr[1]+", Resolution Comment:"+arr[2];
console.log(stringResponse);
}
});
console.log("stringResponse from email",stringResponse);
行:
console.log("stringResponse from email",stringResponse);
是外部 on('data') 回调函数,此行在设置 stringResponse 变量之前调用。把它放在回调函数的末尾(内部)。或者在流结束时调用的另一个回调函数中:
stream.on('data', function(line) {
...
console.log("stringResponse from email",stringResponse); // show each append
});
stream.on('end', function() {
...
console.log("stringResponse from email",stringResponse); // show each append
});
我的节点 js 函数中有以下代码。即使 IF 条件为真,我也没有为字符串 Response 变量更新值。
var fs = require('fs'),
byline = require('byline');
var stream = fs.createReadStream('Solutionbank.csv');
var stringResponse = "We found a similar issue. ";
stream = byline.createStream(stream);
stream.on('data', function(line) {
var csvLine = line.toString('utf8');
csvLine = csvLine.toLowerCase().trim();
var msgText = subject.toLowerCase().trim();
//console.log("email block",msgText);
if(csvLine.indexOf(msgText) > -1) {
var arr = line.toString('utf8').split(",");
stringResponse = stringResponse + "Issue ID"+arr[0]+",Subject : "+arr[1]+", Resolution Comment:"+arr[2];
console.log(stringResponse);
}
});
console.log("stringResponse from email",stringResponse);
行:
console.log("stringResponse from email",stringResponse);
是外部 on('data') 回调函数,此行在设置 stringResponse 变量之前调用。把它放在回调函数的末尾(内部)。或者在流结束时调用的另一个回调函数中:
stream.on('data', function(line) {
...
console.log("stringResponse from email",stringResponse); // show each append
});
stream.on('end', function() {
...
console.log("stringResponse from email",stringResponse); // show each append
});