0

カスタムMXMLDropDownListコンポーネントの2つのインスタンスを使用しているメインアプリがあります。

MySQLにクエリを実行し、ArrayCollectionに結果を入力するために、カスタムコンポーネント内にすべてのロジックとクエリを含めました。

私の最初のDropDownListで、データベースで利用可能なすべての通貨を表示したいと思います。

2番目のDropDownListでは、filterFunctionを使用してCAD通貨とUSD通貨のみを表示したいと思います。

理由はわかりませんが、最初の要素にfilterFunctionが適用されると、2番目の要素は同じcurrencyList変数を共有しているように動作します(これは私の問題です)。

aSyncListViewにバインドするには、currencyListの[Bindable]必要です。

メインアプリで使用するには、currencyListのパブリックが必要です

そして、私の変数がパブリックであるかプライベートであるかに関係なく、同じバグがあります...このメッセージの最後にある出力を参照してください。


私のメインアプリの呼び出しは次のようになります:

<mx:Form>
  <formElems:DropDownListCurrencies id="product_cost_price_curr"
    currencyCadUsdOnly="true"/>
  <formElems:DropDownListCurrencies id="product_price_curr"/>
</mx:Form>

今私のカスタムコンポーネント:

<fx:Script>
    <![CDATA[
        import classes.SharedFunctions;

        import mx.collections.ArrayCollection;
        import mx.controls.Alert;
        import mx.events.FlexEvent;
        import mx.rpc.events.ResultEvent;

        [Bindable]
        public var currenciesList:ArrayCollection;

        public var currencyCadUsdOnly:Boolean = false;

        protected function dropdownlist1_creationCompleteHandler(event:FlexEvent):void
        {
            getAllCurrenciesResult.token = currenciesService.getAllCurrencies();

            // DEBUG just to show the id of the component
            trace('id:' + this.id + ' (getAllCurrencies)');
        }

        protected function getAllCurrenciesResult_resultHandler(event:ResultEvent):void
        {
            currenciesList = getAllCurrenciesResult.lastResult;

            // DEBUG before filterFunction
            trace('id:' + this.id + ', currencyCadUsdOnly:' + currencyCadUsdOnly + ', currenciesList.length:' + currenciesList.length + ' (BEFORE filterFunction)');

            if (currencyCadUsdOnly == true) {
                currenciesList.filterFunction = filterCadUsdOnly;
                currenciesList.refresh();
            }

            // DEBUG after filterFunction
            trace('id:' + this.id + ', currencyCadUsdOnly:' + currencyCadUsdOnly + ', currenciesList.length:' + currenciesList.length + ' (AFTER filterFunction)');
        }

        protected function filterCadUsdOnly(obj:Object):Boolean
        {
            return (obj.code == 'CAD' || obj.code == 'USD');
        }

    ]]>
</fx:Script>

<fx:Declarations>
    <s:CallResponder id="getAllCurrenciesResult" result="getAllCurrenciesResult_resultHandler(event)"/>
    <currenciesservice:CurrenciesService id="currenciesService" fault="SharedFunctions.showError(event.fault.faultString, event.fault.faultDetail)" showBusyCursor="true"/>
</fx:Declarations>

<s:AsyncListView list="{currenciesList}"/>

最後に、コンソールの出力を見てみましょう。2番目のコンポーネントの作成時にArrayListの長さが7になることを期待しています...:

id:product_prices_curr (getAllCurrencies)
id:product_cost_price_curr (getAllCurrencies)
id:product_prices_curr, currencyCadUsdOnly:true, currenciesList.length:7 (BEFORE filterFunction)
id:product_prices_curr, currencyCadUsdOnly:true, currenciesList.length:2 (AFTER filterFunction)
id:product_cost_price_curr, currencyCadUsdOnly:false, currenciesList.length:2 (BEFORE filterFunction)
id:product_cost_price_curr, currencyCadUsdOnly:false, currenciesList.length:2 (AFTER filterFunction)

助けてくれてありがとう!

4

2 に答える 2

1

フィルタが異なる複数の場所に同じリストを配置する必要がある場合は常に、ListCollectionViewが必要です。そうすれば、それにフィルターを適用でき、元のリストに影響を与えることはありません。それは次のように簡単です:

var secondList:ListCollectionView = new ListCollectionView(originalList);

またsecondList、元のリストに影響を与えることなく、好きなフィルターを使用できます。また、アイテムがに追加または削除されたときに更新するという利点もありoriginalListます。

ここを参照してください:mx.collections.ListCollectionView

于 2011-04-06T01:08:41.883 に答える
0

コードを次のように変更してみてください。

        if (currencyCadUsdOnly == true) {
            currenciesList = new ArrayCollection(currenciesList.source);
            currenciesList.filterFunction = filterCadUsdOnly;
            currenciesList.refresh();
        }

お役に立てれば!

于 2011-04-05T23:34:04.633 に答える