在车把中打破#each循环

时间:2014-02-17 10:03:55

标签: html handlebars.js

我在ascx文件中有这样的把手脚本代码。

<script id="ex" type="text/x-handlebars-template">
 {{#each model}}
   {{#if condition}}
  //Need to Break, Dont know how to do that
   {{/if}}
 {{/each}}
</script>

1 个答案:

答案 0 :(得分:2)

只需将此对象传递给javascript函数,执行所需的逻辑并将其返回。

<script type= "text/javascript">
    Handlebars.registerHelper("ifSet", function (model) {        
        var count = 0;
        while (count < model.length) {            
    //    if (logic Condition){
    //      return 'Success';  or Break;             
    //    }
        }
        return;
    });     
</script>

<script id="ex" type="text/x-handlebars-template">
 {{ifSet model}}
</script>