0

我正在尝试使用变量作为索引访问数组,然后像这样输出它:

h3= users[{#id}].first_name

但是由于#{id},我得到了一个“SyntaxError:Unexpected token ILLEGAL”。这样做的正确方法是什么?

4

1 回答 1

3

您可以id不使用散列或花括号。

index.js

exports.index = function(req, res){
  res.render('index', { 
    title: 'Express',
    users: [{first_name: 'John', age: 20}, {first_name: 'Mike', age: 30}],
    id: 1
  });
};

索引.jade

extends layout

block content
  h1= title
  p Welcome to #{title}
  p= users[id].first_name
于 2013-02-18T22:23:37.517 回答