使用 Sitebricks,我想生成一个表,其中一个对象支持表中的每个
。我见过的唯一示例是一个对象返回整个
- 因此每一行的 HTML 都是一致的。我希望能够将 N 个条目包装在
中。
我不想让 Sitebricks 中的页面对象了解页面的布局(因此必须添加索引或将项目构造为 List>
)。
有什么想法吗?
编辑:当然,这不仅限于 Sitebricks,而是关于使用 Web 模板系统将模型与视图分离的一般问题。
Using Sitebricks, I want to generate a table where one object backs each <td>
in a table. The only examples I've seen have one object back an entire <tr>
- so the HTML is consistent across each row. I would like to be able to wrap N entries in <tr>
.
I don't want to have to have my page object in Sitebricks be aware of the layout of the page (and so have to add indices or structure the items as a List<List<Something>>
).
Any ideas?
Edit: This is, of course, not limited to Sitebricks, but is a general question about separation of model from view using web templating systems.
发布评论
评论(2)
是的,您可以在任何标签上添加@Repeat。定义隐式变量
index
和last
供您在重复中执行自己的逻辑。例如,您可以添加 CSS 类 ifindex % 2 == 0
来对甚至行进行不同的着色。这是一个测试用例,显示了它如何适用于非表标签(标签实际上并不重要):
https://github.com/dhanji/sitebricks/blob/master/sitebricks-acceptance-tests/src/main/resources/Repeat.html
Yep, you can add @Repeat on any tag. The implicit variables
index
andlast
are defined for you to do your own logic inside the repeat. You could, for example, add a CSS class ifindex % 2 == 0
to color even rows differently.Here is a testcase showing how this works for non-table tags (the tags really don't matter):
https://github.com/dhanji/sitebricks/blob/master/sitebricks-acceptance-tests/src/main/resources/Repeat.html
似乎你可以将@Repeat放在任何东西的前面。我认为它不关心它是表中的行还是列。
https://github.com /dhanji/sitebricks/blob/master/sitebricks-acceptance-tests/src/main/resources/Repeat.html
如果您想跟踪索引,这样你就可以在每 n 行发出特殊的东西,我不知道。
Seems like you can put the @Repeat in front of anything. I don't think it cares about whether it's a row in a table or a column.
https://github.com/dhanji/sitebricks/blob/master/sitebricks-acceptance-tests/src/main/resources/Repeat.html
If you're trying to keep track of the index so you can emit special stuff every nth row, I don't know.