简体   繁体   中英

Rendering regex data to Jade

So in my code below, I write the data extracted from the regex matches onto the console. However, I need to render this data to a jade file so the user, who uploads the log file, can view the matches himself. Any ideas or sites with information?

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])]
}    
}

UPDATE: So this is what I have tried so far.

Jade file:

...
  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

With this code in my index.js file

/* 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;
}

But it renders an error that logs is undefined. I'm supposing since it does not put the matches into the log entries.

res.render('fileUpload', { title: 'Building a Log File Viewer' }, {logs: logs});

should be

res.render('fileUpload', { title: 'Building a Log File Viewer', logs: logs });

I think that will get logs to be the array inside the jade template, but I don't think your include log is going to treat log as a variable, it's just going to try to include a file called "log.jade". You'll probably need to read the log files in your javascript code to get the data you need as strings and then pass that to jade for inclusion in the HTML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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