Flex3 中的组合框选定项

发布于 2024-08-07 07:48:11 字数 344 浏览 3 评论 0原文

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

如下图所示。

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

就像如果 stylename 被“选中”一样,那么 ComboBox 所选项目也需要被“选中”。

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

提前致谢

i am working in Air application in Flex3 , i need know how to set "selectedItem" Property when we have 2 values like(data and label) label property to combobox selection, data value for our input.

Like shown below.

In (selectedItem="{stylename}") stylename will have "data" value but i need to set that "lable" property as selected value in combobox.

Like if stylename is "checked" then the ComboBox selected item need to be "Checked".

How to implement this in flex ....

Thanks in Advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹梦 2024-08-14 07:48:11

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}" />

ComboBox.selectedItem is looking for an Object. You are passing it a String literal. Where is "stylename" being set? If this is coming from an external source, you can retrieve the item to be selected in a setter function:

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}" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文