我尝试将参数传递给nodejs fs回调函数,但在回调函数中,它无法访问参数,如下所示:
我尝试将索引传递给" line"事件回调,但它失败了,回调内的索引是未定义的。似乎关闭不正确?
如何解决这个问题?
function readLog(path, index) {
var rd = readline.createInterface({
input: fs.createReadStream(path),
output: process.stdout,
terminal: false
});
console.log("index: " + index);
rd.on('line', function (lineContent) {
console.log("index1: " + index);
if (lineContent.indexOf("keyword") > -1) {
keyword = "keyword " + index;
}
});
}