handlerbars.js check if list is empty

前端 未结 5 1056
忘了有多久
忘了有多久 2021-01-31 23:50

Is there a way in Handlebars.js templating to check if the collection or list is null or empty, before going and iterating through the list/collection?

// if lis         


        
5条回答
  •  执笔经年
    2021-02-01 00:24

    If you want to check if a collection (cursor) is empty or not, the previous answers won't be useful, instead you must use the count() method :

    {{#if items.count}}
        

    There is {{items.count}} item(s).

    {{else}}

    There is nothing

    {{/if}}

提交回复
热议问题