Apache flex Flex3中的组合框selectedItem
我在Flex3的Air应用程序中工作,我需要知道当我们有两个值时如何设置“selectedItem”属性,例如(数据和标签)标签属性到组合框选择,输入的数据值 如下图所示 在(selectedItem=“{stylename}”)中,stylename将具有“data”值,但我需要将该“lable”属性设置为combobox中的选定值 就像如果stylename是“选中”的,那么组合框中所选的项目需要“选中” 如何在flex中实现这一点Apache flex Flex3中的组合框selectedItem,apache-flex,actionscript-3,flex3,air,Apache Flex,Actionscript 3,Flex3,Air,我在Flex3的Air应用程序中工作,我需要知道当我们有两个值时如何设置“selectedItem”属性,例如(数据和标签)标签属性到组合框选择,输入的数据值 如下图所示 在(selectedItem=“{stylename}”)中,stylename将具有“data”值,但我需要将该“lable”属性设置为combobox中的选定值 就像如果stylename是“选中”的,那么组合框中所选的项目需要“选中” 如何在flex中实现这一点 提前感谢组合框。selectedItem正在查找对象。
提前感谢
组合框。selectedItem
正在查找对象
。您正在传递一个字符串文本。“样式名”设置在哪里?如果该项来自外部源,则可以在setter函数中检索要选择的项:
行动脚本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:
@vineth,我很好地理解了这个问题-也许英语不是你的第一语言-我希望我的回答对你有所帮助。谢谢Eric先生,我将尝试这种可绑定的方法,因为我已经为selectedItem提供了一种方法,可以像你上面提到的那样重新运行标签值。。
<mx:ComboBox dataProvider="{comboBoxData}" selectedItem="{comboBoxSelectedItem}" />