Defining iterative block helpers in Meteor 0.8

后端 未结 1 1623
终归单人心
终归单人心 2021-01-16 10:37

Until version 0.8 it was possible to use the regular Handlebars way for defining iterative block helpers such as the popular each_with_key, defined, e.g., here

相关标签:
1条回答
  • 2021-01-16 11:01

    And just as I was about to give up, I figure it out. It's in fact easier and prettier now in 0.8 than it was before. The following seems to work great:

    JS:

    UI.registerHelper('addKeys', function (all) {
        return _.map(all, function(i, k) {
            return {key: k, value: i};
        });
    });
    

    HTML:

    {{#each addKeys obj}}
    <div>
       {{key}}: {{value}}
    </div>
    {{/each}}
    
    0 讨论(0)
提交回复
热议问题