简体   繁体   English

有没有办法打破JQuery模板中的{{each}}循环

[英]Is there a way to break the {{each}} looping in JQuery Templates

Is there a way to break the looping defined in the JQuery Template , the one which we used to break any normal loop. 有没有一种方法可以打破JQuery Template中定义的循环,我们曾经用它来打破任何正常的循环。

Thanks in Advance. 提前致谢。

Why not just pass in a smaller collection containing only the values that you do want to loop over? 为什么不只传入一个只包含您想要循环的值的较小集合呢? In general, templates should be "dumb" and contain as little business logic as possible. 通常,模板应该是“哑”的,并且包含尽可能少的业务逻辑。

your templates should not be smart enough to break loops. 您的模板应该不够聪明,无法打破循环。 it should render data, and not process anything. 它应该呈现数据,而不处理任何东西。 there may be a 'proper' way to do this, but this might work if you need to get er done. 可能有一种“正确”的方法来执行此操作,但是如果您需要完成此操作,则此方法可能会起作用。

sudo code... 须藤代码...

continue = true;
{{each}}

{{if continue}}
{{expressionToCheckIfContinue()}}
TEMPLATE BLAH
{{/if}}

{{/each}}

set the continue var to false (from within expressionToCheckIfContinue) when you want to break. 要中断时,将continue var设置为false(从expressionToCheckIfContinue内部)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM