繁体   English   中英

将正则表达式数据呈现给Jade

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM