カスタム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)
助けてくれてありがとう!