如何在 Sitebricks 中生成 HTML 表格?

发布于 2024-12-21 23:05:55 字数 330 浏览 5 评论 0 原文

使用 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

极致的悲 2024-12-28 23:05:55

是的,您可以在任何标签上添加@Repeat。定义隐式变量 indexlast 供您在重复中执行自己的逻辑。例如,您可以添加 CSS 类 if index % 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 and last are defined for you to do your own logic inside the repeat. You could, for example, add a CSS class if index % 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

寻找我们的幸福 2024-12-28 23:05:55

似乎你可以将@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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文