質問

未フォーマットのPriceフィールドを含むFlex 2のデータグリッドにデータを提供するxmlファイルがあります(つまり、単なる数値です)。 誰も私がそのデータフィールドをどのように取り、それをフォーマットするか教えてくれますか? ありがとう。 S。

役に立ちましたか?

解決

前述のように、これを行う簡単な方法は、指定された列にlabelFunctionを追加し、その列内のデータをフォーマットすることです。

頻繁にオブジェクトを操作する方がはるかに簡単であることがわかります。通常、関数からXMLを受け取っている場合は、そのXMLのオブジェクトとパーサーを作成し、必要に応じてパーサー内のデータをフォーマットできます。

これを処理する別の方法は、itemRenderer内です。例:

<mx:DataGridColumn id="dgc" headerText="Money" editable="false">
    <mx:itemRenderer>
      <mx:Component>
         <mx:HBox horizontalAlign="right">
        <mx:CurrencyFormatter id="cFormat" precision="2" currencySymbol="<*>quot; useThousandsSeparator="true"/>
            <mx:Label id="lbl" text="{cFormat.format(data)}" />
         </mx:HBox>
      </mx:Component>
    </mx:itemRenderer>
</mx:DataGridColumn>

他のヒント

ご回答ありがとうございます...彼らは大いに助けてくれました。

最終的に、次の3つの要素を含むソリューションを探しました。

<mx:DataGridColumn headerText="Price" textAlign="right"  labelFunction="formatCcy" width="60"/>

public function formatCcy(item:Object, column:DataGridColumn):String
        {
         return euroPrice.format(item.price);
        }

<mx:CurrencyFormatter id="euroPrice" precision="0" 
    rounding="none"
    decimalSeparatorTo="."
    thousandsSeparatorTo=","
    useThousandsSeparator="true"
    useNegativeSign="true"
    currencySymbol="€"
    alignSymbol="left"/>

これが正しい解決策であるかどうかはわかりませんが、(現時点では)うまくいくようです。 再度、感謝します、 S ...

CurrencyFormatterクラスはどうですか

こちらはFlex 2のドキュメントです。使い方はとても簡単です。

これらのいずれかをDataGrid列のlabelFunctionで使用して、数値をフォーマットできます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top