把手对象键在数组里面

时间:2015-05-19 16:06:53

标签: javascript handlebars.js

使用把手时,是否有办法访问对象的密钥?如果它在一个数组中?

  var context = {
people: [ 
  { firstName: 'Homer', lastName: 'Simpson' },
  { firstName: 'Peter', lastName: 'Griffin' },
  { firstName: 'Eric', lastName: 'Cartman' },
  { firstName: 'Kenny', lastName: 'McCormick' },
  { firstName: 'Bart', lastName: 'Simpson' }
  ]
};

Handlebars有一个内置帮助器来访问对象键,但在链接时它似乎不起作用。

{{#each myObject}}
Key: {{@key}} Value = {{this}}
{{/each}}

是否有已知的结构要返回:

firstName: Homer lastName: Simpson

0 个答案:

没有答案