limit results of each in handlebars.js

前端 未结 4 959
刺人心
刺人心 2020-12-14 07:29

I have written a small plugin that displays tweets. following is the code that loops and displays the tweets.

    

        
4条回答
  •  囚心锁ツ
    2020-12-14 07:54

    "each" is no longer very simple: https://github.com/wycats/handlebars.js/blob/master/lib/handlebars/base.js#L99

    That's because each now supports a whole host of loop information you probably want to still have access to.

    So limiting the data early on is probably preferable if you don't want to reimplement the much more complicated each. You could also try using a subexpression within each (i.e. a {{#each (limit data 6)}} if you're using the latest version of handlebars.

提交回复
热议问题