handlerbars.js check if list is empty

前端 未结 5 1064
忘了有多久
忘了有多久 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:46

    Ok it's simpler than I thought:

    {{#if items}}
    // render items
    
    {{#each items}}
    // render item
    {{/each}}
    
    {{else}}
    // render empty
    {{/if}}
    

提交回复
热议问题