简体   繁体   中英

Express how to pass .json into res.render

How can I pass an object array like this:

var DataArray = [
{"type": "c#", "script":"csharp script"},
{"type": "javascript", "script":"javascript script"},
{"type": "html", "script":"html script"}
]

Into res.render

res.render('index.ejs');

I've tried using the options, but as far as I know that only accepts a string value and I wasn't able to get it working (I received the default [object Object] value)

Any help would be greatly appreciated!

According to the express res.render docs, you can pass locals as the second argument to render . For templating engines, packages that would render html after inserting provided variables, those variables were often called locals .

// pass a local variable to the view
res.render('user', { name: 'Tobi' }, function (err, 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