使用把手时,是否有办法访问对象的密钥?如果它在一个数组中?
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