spark DropDownListのselectedIndex publicプロパティをビューのプレゼンテーションモデルの元のソースにバインドできません。DropDownListのselectedIndexをBindableクラスのselectedIndexメンバーにバインドできません
できるだけ少ない行でこの問題を再現するために、2つのビューと1つのプレゼンテーションモデルがあります。コードは次のとおりです。
Main.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955"
minHeight="600"
xmlns:views="com.blah.views.*">
<views:DropDownListView/>
</s:Application>
DropDownListView.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Script>
<![CDATA[
import com.blah.presentationmodels.DropDownListPresentationModel;
[Bindable]
private var pm:DropDownListPresentationModel = new DropDownListPresentationModel();
]]>
</fx:Script>
<s:DropDownList id="myDropDownList"
dataProvider="{pm.list}"
selectedIndex="{pm.selectedIndex}"
valueCommit="{pm.selectionChanged()}"/>
</s:Group>
DropDownListPresentationModel.as
package com.blah.presentationmodels
{
import mx.collections.ArrayCollection;
[Bindable]
public class DropDownListPresentationModel
{
public var selectedIndex:int = -1;
public var list:ArrayCollection = new ArrayCollection();
public function DropDownListPresentationModel()
{
list.addItem("Load of Bread");
list.addItem("Stick of Butter");
list.addItem("Carton of Milk");
}
public function selectionChanged():void
{
var newSelectedIndex:int = selectedIndex; // always -1
}
}
}
アプリケーションのデバッグプレゼンテーションモデルのselectedIndexは、DropDownListから選択したアイテムに関係なく、常にデフォルト値のままです。上記のサンプルコードでは-1です。
プレゼンテーションモデルでselectedIndexをバインドすると、選択したアイテムDropDownListが変更されたときに適切に更新されます。私は プレゼンテーションモデル内のselectedIndexは関係なく、常に私がDropDownListコントロールから選択された項目の を割り当てられたデフォルト値のままであることを見つけるアプリケーションのデバッグ