Velocity:用“今天”的日期填充列表到过去任意设定的点
我想使用 Velocity 填充一个下拉列表,其中包含从当月到过去固定日期的月份。我不确定这是否可能,因为唯一可用的循环是 foreach 并且我不知道是否有一种明智的方法来填充 foreach 将循环通过的数组。
难道这种事我用 Velocity 根本就做不到吗?我可以使用 Javascript 轻松实现它,但出于可访问性的原因,我更喜欢它由服务器创建。
I want to populate a drop-down list with months from the current month to a fixed date in the past using Velocity. I'm not certain if this is possible, since the only loop that is available is foreach and I do not know if there is a sensible way to populate the array the foreach will loop through.
Is this kind of thing simply not something I can do with Velocity? I could achieve it quite easily with Javascript, but for accessibility reasons I'd prefer it to be created by the server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这绝对可以做到。查看 VelocityTools 项目中的 DateTool 并回想一下,您可以在 VTL 中创建和填充 ArrayList:
或
或 直接:
但实际上,您也可以在 java 中填充数组,然后将其放入上下文中。通常这比在您的视图中构建模型数据更好。
Yes, this can definitely be done. Check out the DateTool from the VelocityTools project and recall that you can create and populate ArrayLists in VTL:
or
or directly:
But really, you can also populate the array in java and then drop it into your context. Often that is better than building model data in your view.