BIRT:How 以访问 Onprepare() 事件的内部 table 中的外部 table 值。?

BIRT:How to access the outer table values in inner table of Onprepare() event.?

我有两个 table。 我无法访问内部 Onprepare() 事件中的外部 table 值 row["Value"] =31=] 在 BIRT 报告中。 所以我可以使用这些值来动态设置内部 table 列的宽度。 如何访问 Onprepare() 事件中的外部 table 值?

列没有方法。如果我把单元格宽度给出错误 12 厘米 堆栈跟踪: org.eclipse.birt.report.engine.api.EngineException: 评估脚本时出现错误 "this.width="12cm";": Wrapped java.lang.UnsupportedOperationException: 无法设置单元格宽度,请设置列宽。 (/report/body/table[@id="3482"]/detail/row[@id="3485"]/cell[@id="3486"]/table[@id="98041" ]/detail/row[@id="98063"]/cell[@id="98066"]/method[@name="onCreate"]#1)

在外部 table 的行中,您可以将一些行值写入变量。
在内部 table 您可以访问该变量。

编辑: 您需要具有全局访问范围的 "variable"。一种方法是在报告的 initialize() 脚本中初始化变量(beforeFactory() 或 onPrepare() 也是有效选项)

myVar1 = 0;     //has global scope
var myVar2 = 0; //has only local scope

→ 尝试将您的 innerTable 脚本从 onPrpare() 移动到 onCreate()

here's a simple example report(更新了具有动态宽度的链接示例)

在该示例中,我将 1 | 2 | 3 的值从外部传递到内部 table。 在内部 table 的 onCreate() 中,您可以将该值与适当的单位连接起来,例如。 cmin。 还要检查您是否有 'Fixed Layout'(不是 'Auto Layout')的报告。

//"this" is the table
this.width = myVar1 + ' cm'; // set inner table width

编辑:设置内部 table 列的宽度而不是 table 宽度本身也可以从内部 table 的 onCreate() 完成。

/* initialize() of Report */
dynColWidth = null; // initialize a var with global scope to store an array

/* onCreate() of outerTable's Cell (using a DynamicText Field makes it more obvious) */
dynColWidth = [1*row["ID"], 2*row["ID"]];  // create the array with your 12 values here

/* onCreate() of innerTable ("this" is the table) */
var i;
for(i=0; i<this.getColumnCount(); i++) {
  this.getColumn(i).width = dynColumnWidth[i] + 'cm';
}