我在Flex3的空气应用程序中工作,我需要知道如何设置"selectedItem“属性时,我们有2个值,如(数据和标签)标签属性到组合框的选择,数据值为我们的输入。
如下所示。
在(selectedItem=“{selectedItem=}”)中,样式名将具有"data“值,但我需要在组合框中将"lable”属性设置为选定值。
例如,如果样式名为"Checked“,则ComboBox选定项需要"checked”。
如何在flex中实现这一点...
提前感谢
发布于 2009-10-15 14:25:35
ComboBox.selectedItem正在寻找Object。您正在向它传递一个String文本。"stylename“设置在哪里?如果它来自外部源,您可以在setter函数中检索要选择的项:
ActionScript 3:
[Bindable]
public var comboBoxData:ArrayCollection;
[Bindable]
private var comboBoxSelectedItem:Object = {};
private var _styleName;
private function get styleName():String
{
return _styleName;
}
private function set styleName(value:String):void
{
_styleName = value;
comboBoxSelectedItem = getItemFromCollection("styleName", value);
}
private function getItemFromCollection(property:String, value:String):Object
{
// Create a copy of the Collection used as the dataProvider for the ComboBox
var filteredCollection:ArrayCollection =
new ArrayCollection(comboBoxData.toArray());
// Set a filterFunction to filter only those Objects with the specified name/value pair
filteredCollection.filterFunction =
function(item:Object):Boolean
{
return item[property] == value;
}
// Refresh the collection to apply the filterFunction
filteredCollection.refresh();
// Return an empty Object if no Object was found with the given name/value pair
if (filteredCollection.length == 0)
return {};
// Return the first/only Object in the filtered Collection
return filteredCollection.getItemAt(0);
}MXML:
<mx:ComboBox dataProvider="{comboBoxData}" selectedItem="{comboBoxSelectedItem}" />https://stackoverflow.com/questions/1571070
复制相似问题