简体   繁体   English

我如何遍历 Jasper 中的列表?

[英]How do I iterate over a list in Jasper?

I can't seem to find any information out there on this, but basically this is the situation.我似乎无法找到任何关于此的信息,但基本上就是这种情况。 I need to display a set of strings, in this case they are peroids of hours.我需要显示一组字符串,在这种情况下,它们是几个小时的周期。 I'm trying to avoid writing a Java class but I can do that if it's necessary.我试图避免写一个 Java class 但如果有必要我可以这样做。 Basically I want to display something like基本上我想显示类似的东西

1-2pm
2-3pm
3-4pm
4-5pm

I tried creating a list and a variable and then just doing我尝试创建一个列表和一个变量然后只是做

new ArrayList

assigning that to a variable and then doing a将它分配给一个变量然后做一个

$V{my_var}.add("1-2pm")

but when I assign that variable to a list it doesn't seem to work.但是当我将该变量分配给列表时,它似乎不起作用。 How is this normally handled?这通常是如何处理的? I would ideally want a way to simply do this with the expression editor.理想情况下,我想要一种使用表达式编辑器简单地执行此操作的方法。

You can use Arrays.asList(T... a) method in variable expression.您可以在变量表达式中使用Arrays.asList(T... a)方法。

The example:这个例子:

<variable name="listVar" class="java.util.List">
    <variableExpression><![CDATA[Arrays.asList(new String[] {"1-2pm", "2-3pm", "3-4pm", "4-5pm"})]]></variableExpression>
    <initialValueExpression><![CDATA[Arrays.asList(new String[] {"1-2pm", "2-3pm", "3-4pm", "4-5pm"})]]></initialValueExpression>
</variable>

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

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