How to find Array length inside the Handlebar templates?

后端 未结 4 1012
误落风尘
误落风尘 2021-02-01 11:43

I have a Handlebars template which is rendered using a json object. In this json I am sending an array. Like this:

var json = {
               \"array\":[\"abc\"         


        
4条回答
  •  生来不讨喜
    2021-02-01 12:15

    You can define simple helper to handle it:

    Handlebars.registerHelper('get_length', function (obj) {
     return obj.length;
    });   
    

    And then use it in your template eg:

    {{get_length some_object}}
    

提交回复
热议问题