سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top