[英]Rendering regex data to Jade
因此,在下面的代碼中,我將從正則表達式匹配中提取的數據寫入控制台。 但是,我需要將此數據渲染到一個玉文件中,以便上載日志文件的用戶可以自己查看匹配項。 有任何想法或網站信息嗎?
while ((match = reDiaBtoa.exec(newArray[j])) != null) {
if (match.index === reDiaBtoa.lastIndex) {
reDiaBtoa.lastIndex++;
}
if (match[2] === "ERROR") {
console.log(match[2]);
console.log("Time " + match[1]);
console.log("Thread Name: " + match[3]);
console.log("Source name & line number: " + match[4]);
console.log("Log Message: " + match[5] + '\n');
console.log("-----------------------------------------------------------------" + "\n");
var logs = [new Log(match[1], match[3], match[4], match[5])]
}
}
更新:這就是我到目前為止所嘗試的。
玉文件:
...
form(method="post", action="/upload", enctype="multipart/form-data")
input(type="file", name="logName")
button(type="submit") Upload
h1.
Log List
#logs
for log in logs
include log
在我的index.js文件中包含此代碼
/* GET home page. */
router.get('/', function (req, res) {
res.render('fileUpload', { title: 'Building a Log File Viewer' }, {logs: logs});
});
function Log(time, thread, source, mess) {
this.time = time;
this.thread = thread;
this.source = source;
this.mess = mess;
}
但這會導致錯誤,即日志未定義。 我猜想是因為它不會將匹配項放入日志條目。
res.render('fileUpload', { title: 'Building a Log File Viewer' }, {logs: logs});
應該
res.render('fileUpload', { title: 'Building a Log File Viewer', logs: logs });
我認為這將使logs
成為jade模板中的數組,但是我不認為您的include log
會將log
視為變量,而只是嘗試包含一個名為“ log.jade”的文件。 您可能需要讀取javascript代碼中的日志文件,以獲取所需的數據作為字符串,然后將其傳遞給jade以包含在HTML中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.