1

Orbeon フォーム ビルダーで eform を開発しています。ここでは、リピーター (新しいリピート) コントロールを使用しています。そのコントロール内には、テキスト コントロールの行が多数あります。ユーザーがそれらのコントロールに挿入する値を使用して計算を行いたいと思います。「商品数」と「単価」の2つの列があるとします。内部には多くの行があります。つまり、ユーザーは動的に値を挿入します。

このリピーター コントロールの隣にはテキスト コントロールがあり、ボタン イベントなしで合計金額を表示する必要があります。

たとえば、テーブルのようなリピータ構造があるとします:

column name(Number of items---unit price)
 first value(1 ----100)
 second value(5----200)

合計金額は、テキスト コントロールに 1100 として表示する必要があります。ユーザーによっては、グリッドの数が増える場合があります (ここでは 2 です)。

4

1 に答える 1

0

総コストを調べるには、通常の計算トリックを思いつくことができませんでした。そこで、この問題を解決するためにかなり小さな XQuery を使用しました。

フォーム ビルダーを使用しているのか、Xforms コーディングを「手作業で」使用しているかはわかりませんが、「手作業で」開発しています。以下は、Orbeon Xforms Sandbox で実行できる完全な Xforms コードです。

<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:f="http://orbeon.org/oxf/xml/formatting"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
    xmlns:ev="http://www.w3.org/2001/xml-events"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    >

    <xhtml:head>

        <xforms:model xmlns:xforms="http://www.w3.org/2002/xforms"
                xmlns:xs="http://www.w3.org/2001/XMLSchema" id="main-model">

          <xforms:instance id="form-instance">
            <form>
                <sale>
                    <number-of-units>1</number-of-units>
                    <unit-price>100</unit-price>
                </sale>
                <sale>
                    <number-of-units>2</number-of-units>
                    <unit-price>500</unit-price>
                </sale>
            </form>
          </xforms:instance>


        </xforms:model>
    </xhtml:head>

    <xhtml:body>

      <table>
        <tr>
            <td>
                Total price:
            </td>
            <td>
                <xforms:output value="sum(
                                        for $i in instance('form-instance')/sale
                                            return $i/number-of-units * $i/unit-price
                                        )
                                        " /> 
            </td>
        </tr>
      </table>

    </xhtml:body>
</xhtml:html>

ブラウザ出力:

ここに画像の説明を入力

フォーム ビルダーを使用している場合は、必要に応じて結果式を取得し、バインド定義の計算属性に使用できます。

表現:

sum(
    for $i in instance('form-instance')/sale
        return $i/number-of-units * $i/unit-price
    )                                           

幸運を!

于 2012-10-13T08:46:48.833 に答える