当用户从第一个下拉框中选择一个类别时,我希望根据第一个下拉列表的选择更新第二个下拉列表。
我创建了多个ArrayCollections,其名称设置为第一个下拉列表的“data”值,例如:
[Bindable]
public var countries:ArrayCollection = new ArrayCollection([
{label:"USA",data:"USA"},
{label:"Canada",data:"Canada"}, ]);
[Bindable]
public var USA:ArrayCollection = new ArrayCollection([
{label:"state1",data:"state1"},
{label:"state2",data:"state2"},
{label:"state3",data:"state3"}, ]);
[Bindable]
public var Canada:ArrayCollection = new ArrayCollection([
{label:"statea",data:"statea"},
{label:"state2b",data:"stateb"},
{label:"statec",data:"statec"}, ]);
[Bindable]
public var Italy:ArrayCollection = new ArrayCollection([
{label:"statex",data:"statex"},
{label:"statey",data:"statey"},
{label:"statez",data:"statez"}, ]);
,列表实现为:
<mx:FormItem label="State:" color="black" required="true">
<s:DropDownList id="state" prompt="Select State" dataProvider="{country.selectedItem.data}">
</s:DropDownList>
</mx:FormItem>
任何想法如何实现这一目标?基本上我需要知道如何正确更新列表的dataprovider以使用正确的arraycollection。
答案 0 :(得分:2)
您可以改为将数据更改为嵌套数据,如下所示:
[Bindable]
public var countries:ArrayCollection = new ArrayCollection([
{label:"USA", data: // country
new ArrayCollection([ // its states, nested
{label:"state1",data:"state1"},
{label:"state2",data:"state2"},
{label:"state3",data:"state3"}
])
},
{label:"Canada",data: // country
new ArrayCollection([ // its states, nested
{label:"state1",data:"state1"},
{label:"state2",data:"state2"},
{label:"state3",data:"state3"}
])
}
]);
然后只需绑定所选项目:
<mx:FormItem label="State:" color="black" required="true">
<s:DropDownList id="state" prompt="Select State"
dataProvider="{country.selectedItem.data}">
</s:DropDownList>
</mx:FormItem>
答案 1 :(得分:1)
收听第一个下拉列表的更改事件并执行以下操作:
state.dataProvider = this[country.selectedItem.data]
'this'关键字引用当前组件,并且使用括号语法将使用状态dataProvider中的字符串值来访问组件上的变量。