【发布时间】:2022-01-30 04:18:16
【问题描述】:
我正在浏览有关 node.js 的各种教程并表达,但找不到代码的这个特定部分实际上在做什么。下面是res.render的第二个参数。我不确定的部分是mascots: mascots 部分。这是在声明 mascots 变量吗?我在javascript语言中找不到像这样完成的任何地方,所以我很困惑他们从哪里得到这个。当然,我刚刚开始学习 Javascript,所以它可能在某个显而易见但还没有找到的地方。看起来它是一个对象(大括号 {} 的 b/c),但即使是,命名吉祥物的价值我也不清楚。这是他们所指的objects 的array 吗?如果是这样,我仍然很困惑。经过一番搜索,我可以得到答案,所以在这里问。
app.get('/', function(req, res) {
var mascots = [
{name: 'Sammy', organization: 'DigitalOcean', birth_year: 2012},
{name: 'Tux', organization: 'Linux', birth_year: 1996},
{name: 'Moby Dick', organization: 'Docker', birth_year: 2013},
];
var tagline = "No programming concept is complete without a cute animal mascot";
res.render('pages/index', {
mascots: mascots, // this line and the one below is what I am not understanding
tagline: tagline
});
});
此特定教程位于此处以供参考:https://www.digitalocean.com/community/tutorials/how-to-use-ejs-to-template-your-node-application 很好的介绍,我了解除了这两行之外的所有内容。
【问题讨论】:
标签: javascript node.js express