简体   繁体   English

birt报告中的嵌套循环

[英]Nested loop in birt report

I'm using Eclipse Birt to generate report from a JSON File. 我正在使用Eclipse Birt从JSON文件生成报告。

My JSON file look like this : 我的JSON文件如下所示:

{  
"cells":[  
  {  
     "type":"basic.Sensor",
     "custom":{  
     "identifier":[  
           {  
              "name":"Name1",
              "URI":"Value1"

           },
           {  
              "name":"Name4",
              "URI":"Value4"
           }
        ],
        "classifier":[  
           {  
              "name":"Name2",
              "URI":"Value2"
           }
        ],
        "output":[  
           {  
              "name":"Name3",
              "URI":"Value3"
           }
        ],

     },
           "image":{  
           "width":50,
           "height":50,
           "xlink:href":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAABEJAAARCQBQGfEVAAAABl0RVh0U29mdHdhcmUAd3Vi8f+k/EREURQtsda2Or/+nFLqP6T5Ecdi0aJFL85msz2Qxyf4JIumMAx/ClmWt23GmL1kO54CXANAVH+WiN4Sx7EoNVkU3Z41BDHMeXAxjvOxNr7RJjzHX7S/jAflwBxkJr/RwiOpWZ883Nzd+Wpld7tkBr/SJr7ZHZbHZeuVweSnPfniocMAWYwcGBafH0OoPamFGAaY4ZBZjmmFGAaY4ZBZjmmFGAaY4ZBZjmmFGAaY7/B94QnX08zxKLAAAAAElFTkSuQmCC"
        }
     }
  },
  {  
     "type":"basic.Sensor",

     "custom":{  
        "identifier":[  
           {  
              "name":"Name1",
              "URI":"Value1"

           },
           {  
              "name":"Name4",
              "URI":"Value4"
           }
        ],
        "classifier":[  
           {  
              "name":"Name2",
              "URI":"Value2"
           }
        ],
        "output":[  
           {  
              "name":"Name3",
              "URI":"Value3"
           }
        ],

     },

        "image":{  
           "width":50,
           "height":50,
           "xlink:href":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9igAQAAAgAIoAEAAAIACKABAAACAAigAQAAAgAIoAEAAAIACKABAAACAAigAQAAAgAIoAEAAAIADqhvprADeSsau00l5NAAAAAElFTkSuQmCC"
        }
     }
  },
  {  
     "type":"basic.Platform",

     "custom":{  
        "identifier":[  
           {  
              "name":"Name1",
              "URI":"Value1"

           }
        ],
        "classifier":[  
           {  
              "name":"Name2",
              "URI":"Value2"
           }
        ],
        "output":[  
           {  
              "name":"Name3",
              "URI":"Value3"
           }
        ],

        "image":{  
           "width":50,
           "height":50,
           "xlink:href":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAA6TH0jqtg6U8EsCdnm3SpevSK7Pb85xABEMBuLAn2hxjRve7SFzYEaB/HhytLQ4ABRwCWBPvBKnRk6U8EkBeOD9f7iwAGHAGEYEmwDxLvzNKfCCDP8NGLQd3lY7D0JwI4kmlwfHhX6dTSXxsRAAHsWR7aUjc7uM5Wg=="
        }
     }
  }
]
 }

i have 3 cells and each one contains 1 Image 1 Name 1 Type and 3 Tables , this is what i have done so far : 我有3个单元格,每个单元格包含1个图像1名称1类型和3个表格,这是我到目前为止所做的: 在此输入图像描述

what i'm struggling to do is a nested loop, i want to have for each object( Cell) in my JSON a paragraph numerated like this : 我正在努力做的是一个嵌套循环,我希望我的JSON中的每个对象(Cell)都有一个如下所示的段落:

  • 2.x Component cell's Name : 2.x组件单元名称:
    • Image 图片
    • Output Table 输出表
    • Identifier Table 标识符表
    • Classifier Table 分类表

So to do this i need to itterate on each cell and then itterate on each table Output, identifier and classifier and i have no idea how can i do this, a nested loop. 所以要做到这一点,我需要在每个单元格上进行迭代,然后在每个表格上输出输出,标识符和分类器,我不知道我该怎么做,一个嵌套循环。 like a List which represent the number of cells, that contains 3 tables, one image , one name. 比如表示单元格数量的List,包含3个表,一个图像,一个名称。

**Edit : ** this is the open method for the data set **编辑:**这是数据集的开放方法

// Grab the JSON file and place it in a string
fisTargetFile = new FileInputStream(new File("C:/Users/Sample Reports/moe.json"));
input = IOUtils.toString(fisTargetFile, "UTF-8");

// Store the contents in a variable
jsonData = input;

// Convert the String to a JSON object
myJSONObject = eval( '(' + jsonData + ' )' );

// Get the length of the object
len = myJSONObject.cells.length;

// Counter
count = 0;

Fetch method : 获取方法:

if(count < len) {
var name     = myJSONObject.cells[count].attrs.text["text"];
var type    = myJSONObject.cells[count].type;
var icon =myJSONObject.cells[count].attrs.image["xlink:href"];



icon = icon.split(",");

icon= icon[1];
imageDataBytes = icon;

row["name"]     = name;
row["type"]    = type;
row["icon"]    = Base64ToBlob.toBytes(icon);



Logger.getAnonymousLogger().info( row["icon"]);
count++;
return true;
}

return false;

You want to use nested tables, there is a good tutorial showing how to link nested tables to an outer table: please watch carefully this demo first, in particular see how the sub-table is linked to the outer table through a dataset parameter. 您想要使用嵌套表,有一个很好的教程显示如何将嵌套表链接到外部表:请首先仔细观察此演示 ,特别是通过数据集参数查看子表如何链接到外部表。

Of course your case is more challenging because you need to do this with scripted datasets and multiple sub-tables. 当然,您的情况更具挑战性,因为您需要使用脚本化数据集和多个子表来执行此操作。 I already did something similar, you have to create one scripted dataset for each sub-table. 我已经做了类似的事情,你必须为每个子表创建一个脚本数据集。 Key-points are: 关键点是:

  • In "parameters" section of each sub-dataset, create one input parameter and name it for instance "systemID" 在每个子数据集的“参数”部分中,创建一个输入参数并将其命名为“systemID”
  • Create your sub-tables by "drag & drop" each dataset within the outer table 通过“拖放”外部表中的每个数据集来创建子表
  • In "bindings" section of each sub-table, link parameter "systemID" to the ID field of the outer table 在每个子表的“绑定”部分中,将参数“systemID”链接到外部表的ID字段
  • In "open" event of sub-datasets, access the value of the parameter with this expression: inputParams["systemID"] Thus you can filter related rows in " myJSONObject ". 在子数据集的“open”事件中,使用以下表达式访问参数的值: inputParams [“systemID”]因此,您可以过滤“ myJSONObject ”中的相关行。
  • It is important to make sure " myJSONObject " is initialized once for all , otherwise performances could dramatically decrease if it is evaluated on each iteration. 确保“ myJSONObject一次性初始化是很重要的,否则如果在每次迭代时对性能进行评估,性能可能会大大降低。 For example evaluate it in "initialize" event of the report. 例如,在报告的“初始化”事件中对其进行评估。

That's it, it won't be easy but these elements should help to achieve this report. 就是这样,它并不容易,但这些元素应该有助于实现这一报告。

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

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