문제

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