我在我的Node.js网页应用程序中使用express.js
,用户输入一些条件,然后程序获取像这样的数据数组:
var data = [
{
name: 'Salmons Creek',
image: 'https://farm6.staticflickr.com/5479/11694969344_42dff96680.jpg',
description: "Great place to go fishin' Bacon ipsum dolor amet kielbasa cow"
},
{
name: 'Granite Hills',
image: 'https://farm5.staticflickr.com/4103/5088123249_5f24c3202c.jpg',
description: "It's just a hill. Made of granite. Nothing more! Cow doner."
},
{
name: 'Wildwood Miew',
image: 'https://farm5.staticflickr.com/4016/4369518024_0f64300987.jpg',
description: 'All campsites. All the time.Short ribs pastrami drumstick.'
},
{
name: 'Lake Fooey',
image: 'https://farm7.staticflickr.com/6138/6042439726_9efecf8348.jpg',
description: 'Hills and lakes and lakes and hills. Pork ribeye pork chop.'
}
];
我想使用EJS模板语言渲染数组中的所有对象。我该如何将数据传递给模板并进行渲染?
res.render('page1', {data:data})
的操作。然后,数据应该可用于您的EJS脚本。 - Keith