首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Flex3中的ComboBox selectedItem

Flex3中的ComboBox selectedItem
EN

Stack Overflow用户
提问于 2009-10-15 08:36:24
回答 1查看 4.4K关注 0票数 1

我在Flex3的空气应用程序中工作,我需要知道如何设置"selectedItem“属性时,我们有2个值,如(数据和标签)标签属性到组合框的选择,数据值为我们的输入。

如下所示。

在(selectedItem=“{selectedItem=}”)中,样式名将具有"data“值,但我需要在组合框中将"lable”属性设置为选定值。

例如,如果样式名为"Checked“,则ComboBox选定项需要"checked”。

如何在flex中实现这一点...

提前感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-10-15 14:25:35

ComboBox.selectedItem正在寻找Object。您正在向它传递一个String文本。"stylename“设置在哪里?如果它来自外部源,您可以在setter函数中检索要选择的项:

ActionScript 3:

代码语言:javascript
复制
[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:

代码语言:javascript
复制
<mx:ComboBox dataProvider="{comboBoxData}" selectedItem="{comboBoxSelectedItem}" />
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1571070

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档