简体   繁体   English

BIRT 报告 JSON 数组打印值

[英]BIRT Report JSON array printed values

I'm trying to print out JSON values from a database column into multiple lines in my Birt report.我正在尝试将 JSON 值从数据库列打印到我的 Birt 报告中的多行中。 It prints the last line of the JSON array just fine, but not the lines before it.它打印 JSON 数组的最后一行就好了,但不会打印它之前的行。

My code for my dynamic text field:我的动态文本字段代码:

var phone = JSON.parse(row["c_numbers"]);
for(var k in phone) {
    phone[k]['type']+': '+phone[k]['phone']
}

This is what it prints:这是它打印的内容:

在此处输入图片说明

And here is the JSON from the database:这是来自数据库的 JSON:

[{"type": "Cell", "phone": "123-123-1233"}, {"type": "", "phone": "123-423-4123"}]

Easiest would be just to print it out, but it's not doing more than the last array item.最简单的方法就是将它打印出来,但它所做的并不比最后一个数组项多。 Report design:报告设计:

在此处输入图片说明

So it's getting the data, iterating over the JSON, and printing, but not all array items, only the last one.所以它获取数据,遍历 JSON 并打印,但不是所有的数组项,只有最后一个。

Answer was to assign the new data to a new variable, then print out that final variable at the end.答案是将新数据分配给一个新变量,然后在最后打印出该最终变量。 I also had to add <br> for a newline at the end of each output.我还必须在每个输出的末尾添加<br>作为换行符。

var phone = JSON.parse(row["c_numbers"]);
var finalPhone = '';

for(var k in phone) {
    finalPhone = finalPhone+(phone[k]['type'] > '' ? phone[k]['type']+': ' : '')+phone[k]['phone']+"<br>"
}

finalPhone;

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

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