简体   繁体   English

表达如何将.json 传入 res.render

[英]Express how to pass .json into res.render

How can I pass an object array like this:如何像这样传递 object 数组:

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

Into res.render进入 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)我试过使用这些选项,但据我所知,它只接受一个字符串值,我无法让它工作(我收到了默认的 [object Object] 值)

Any help would be greatly appreciated!任何帮助将不胜感激!

According to the express res.render docs, you can pass locals as the second argument to render .根据 express res.render文档,您可以将locals作为第二个参数传递给render For templating engines, packages that would render html after inserting provided variables, those variables were often called locals .对于模板引擎,在插入提供的变量后会呈现 html 的包,这些变量通常称为locals

// pass a local variable to the view
res.render('user', { name: 'Tobi' }, function (err, html) {
  // ...
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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