Question

With a simple code of

{{#each array}}
{{@index}}: {{this}}
{{/each}}

a flood of errors appears. Same happens with {{@key}} for objects. Why does it happen?

Était-ce utile?

La solution

Looking at the source (at https://github.com/meteor/meteor/blob/master/packages/handlebars/parse.js): It doesn't look like the {{@ ..}} set of expressions are supported with the Handlebars version packaged with Meteor.

Autres conseils

This is definitely a frustration for me as well. In the meantime I made a handlebars helper to parse anything into named 'key' and 'value' objects:

Handlebars.registerHelper('key_value', function(context, options) {
  var result = [];
  _.each(context, function(value, key, list){
    result.push({key:key, value:value});
  })
  return result;
});

This would be used with the #each operator like:

<dl class="attributes">
  {{#each key_value attributes}}
    <dt>{{key}}</dt><dd>{{value}}</dd>
  {{/each}}
</dl>

(I also just posted this to related Using @index in meteor #each iterator doesn't work)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top