迭代(for循环)一目了然 [英] Iteration (for loop) in sightly

查看:22
本文介绍了迭代(for循环)一目了然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 jstl 中使用过 <c:forEach>.现在我想用视力.

I had used <c:forEach> in jstl. Now i want to use sightly.

我的用例是打印从 1 到 10 的数字,那么我如何像 java 中的 for 循环 一样进行迭代

My usecase is to print numbers from 1 to 10 then how can i iterate in sightly as for loop in java

推荐答案

Sightly 不允许您在设计时将任何逻辑放入其中.您应该做的是,您应该自定义您的基础模型,以便您可以检索包含需要显示的数据的不相关(从 Sightly 的角度)长度的准备列表.之后,只需使用 data-sly-list.您需要谷歌了解更多详细信息,但总的来说,这是您在 Sightly 中使用列表的方式:

Sightly doesn't let you put any logic in it by design. What you should do is, you should customize your underlying model so that you can retrieve a prepared list of irrelevant (from Sightly's perspective) length that contains data that needs to be displayed. After that, just use data-sly-list. You'll need to google for more details, but in general, this is how you use lists in Sightly:

<ul data-sly-list.myitem="${mymodel.myitems}" data-sly-unwrap>
  <li>${myitem.foo}</li>
</ul>

正如@nateyolles 所指出的,您可以通过在测试条件中使用索引来迭代特定范围的项目(<li data-sly-test="${itemList.count >= 2 && itemList.count <= 6}">${item}</li>),虽然我不确定这是否是视觉方式".就个人而言,我建议不要这样做,除非它会让你的生活明显更轻松.

As pointed out by @nateyolles, you can iterate over a specific range of items by using the index in a test condition (<li data-sly-test="${itemList.count >= 2 && itemList.count <= 6}">${item}</li>), though I am not sure if this is the "Sightly way". Personally, I would advise not to, unless it would make your life noticeably easier.

这篇关于迭代(for循环)一目了然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆