在重复控制中获得列平均值

时间:2013-06-12 07:48:16

标签: xpages repeat

我有一个包含五列的重复控件,其值为“2.30”或“1.78”(保存为数值)。

我现在想在重复控件下面创建一个列总计,计算列值的平均值,例如:(2.30 + 1.78)/ 2

我知道如何获取重复控件中的文档数量,但如何获取列的所有值?

getComponent("repeat1").getRowCount()

1 个答案:

答案 0 :(得分:1)

您可以使用重复控件的var属性来访问整行的值并将它们保存在viewScope中。你可以随心所欲地对待他们:

  <xp:repeat id="repeat1" rows="30" value="#{view1}" var="entry"
            indexVar="indexvar">
            <xp:panel>
                <xp:text escape="true" id="computedField1">
                    <xp:this.value><![CDATA[#{javascript:var values:java.util.Vector = entry.getColumnValues();
    var array = (viewScope.add == null)? new Array():viewScope.add;
    array.push(values.elementAt(/* column */1))
    viewScope.put("add",array);
    return indexvar;
    }]]></xp:this.value>
                </xp:text>
            </xp:panel>
        </xp:repeat>

然后你可以显示它们或任何你需要的东西:

<xp:text value="#{viewScope.add}">