データバインディングに問題があります。誰かが助けてくれることを願っています。
私が達成しようとしていることの非常に簡単な例を作成しました。これを以下に示します。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="center" verticalAlign="middle" initialize="init()">
<!-- Controller -->
<mx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
import mx.binding.utils.BindingUtils;
protected var _tally:Number = 3;
//RAW XML
[Bindable]protected var _model:XML = new XML("<model><option title='Option 1'/> <option title='Option 2'/> <option title='Option 3'/> </model>");
//This should bind the children to the XMLLList BUT DOES NOT
[Bindable]protected var _list:XMLList = new XMLList(_model.children());
//This Binds the _list to the _collection
[Bindable]protected var _collection:XMLListCollection = new XMLListCollection(_list);
//ADDS NEW DATA TO MODEL
protected function updateModel():void
{
_tally++;
_model.appendChild(new XML("<option title='Option " + _tally + "'/>"))
trace(_model)
}
]]>
</mx:Script>
<!-- View -->
<mx:Panel title="Combo Binding Test" >
<mx:ComboBox id="_combo" width="100%" labelField="@title" dataProvider="{_collection}" />
<mx:Text id="_text" height="100" width="300" selectable="false" text="{_model}" />
<mx:ApplicationControlBar width="100%" dock="true">
<mx:Button label="Update Model" click="updateModel()" />
</mx:ApplicationControlBar>
</mx:Panel>
</mx:Application>
(うまくフォーマットされていることを願っています!)
これをプレビューすると、バインディングによってデータが正しい場所に配置されていることがわかりますが、より多くのデータで XML を更新すると、ビューが更新されません。
2 つの問題が存在します。
_list.dataProvider から「children()」を削除すると、ComboBox はバインディングを使用して更新されますが、子を読み取る必要があるため、バインディングは失敗します。
モデルがバインド可能として定義されているにもかかわらず、テキストは決して更新されません。
children() にバインドする理由
親からさまざまなデータ セットを受け取るカスタム コンポーネントを作成しました。このカスタム コンポーネント内には、データの子を表示する必要がある ComboBox があります。子にバインドできない場合は、使用されるインスタンスごとに一意のコンポーネントをハードコードする必要がある場合があります。
たとえば、データのインスタンスは次のようになります。
<locations>
<option title="Hampshire"/>
<option title="Warwickshire"/>
<option title="Yorkshire"/>
</locations>
別の可能性があります:
<stock>
<option title="Hammer"/>
<option title="Drill"/>
<option title="Spanner"/>
</stock>
したがって、children() にバインドすることが重要です。
これは可能ですか?そうでない場合、この問題を回避する方法を誰かが知っていますか?
これに関するアドバイスは大歓迎です。