我们将json作为值列表 “ markets”:[{“ id”:“ 1001”,“ name”:“ val1”},{“ id”:“ 1002”,“ name”:“ Val2”},{“ id”:“ 1003”, “ name”:“ val3”}]
使用jasper报告列表组件,我们要显示这些名称属性逗号值的列表,这些值分隔在一个文本字段中。
对于现有列表,name的值仍将作为我们想要的行出现 这样的单个文本字段 vale1,val2,val3
我们如何使用jasper报告列表遍历值并在单个文本字段中显示为逗号分隔。
谢谢, Anjana
答案 0 :(得分:0)
您不需要列表,您可以像这样使用变量:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Report" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3c4d8e3d-d3d5-4cb4-9b07-c67ce217d8dd">
<queryString language="jsonql">
<![CDATA[..name]]>
</queryString>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="[0]"/>
</field>
<variable name="NameConcat" class="java.lang.String">
<variableExpression><![CDATA[$V{NameConcat} != null ? $V{NameConcat} + ", " + $F{name} : $F{name}]]></variableExpression>
</variable>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="180" y="10" width="200" height="30" uuid="fe01a39a-03e4-4a94-b9f7-3317caff6ae3"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14"/>
</textElement>
<text><![CDATA[Concatenated values test]]></text>
</staticText>
</band>
</title>
<columnHeader>
<band height="30" splitType="Stretch">
<staticText>
<reportElement mode="Opaque" x="0" y="0" width="180" height="30" forecolor="#000000" backcolor="#9AFBFC" uuid="59c0da96-00aa-4959-bdc4-4c9b9f7a2e2c">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="748e4fce-3f0c-4df0-836a-45f9a92ac8b8"/>
</reportElement>
<textElement textAlignment="Left" verticalAlignment="Middle">
<paragraph leftIndent="10"/>
</textElement>
<text><![CDATA[Concatenated names]]></text>
</staticText>
</band>
</columnHeader>
<summary>
<band height="30">
<textField isStretchWithOverflow="true">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="180" height="30" uuid="2968b744-4b20-47cf-9fcb-05de58d606d0"/>
<textElement verticalAlignment="Middle">
<paragraph leftIndent="10"/>
</textElement>
<textFieldExpression><![CDATA[$V{NameConcat}]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>