如何在flex4下拉列表中保留提示/虚拟项目

发布于 2024-11-05 03:20:25 字数 601 浏览 0 评论 0原文

我有一个“选择员工”的下拉列表,这是可选的。我需要它在顶部有“No one”,这样如果用户已经选择了“John Something”,他就可以改回NoOne。

我的问题是如何保留提示项,或在 -1 处添加虚拟项而不更改数据提供者(我真的很讨厌在原始的雇员列表数据提供者中添加“没有人”)

P/S:同样的问题但仍然没有答案:

I have a dropdownlist of "Select an employee" which is optional. I need it to have "No one" at the top so that user can change back to NoOne if he' ve already chosen "John Someone".

My question is how to keep the prompt item, or add a dummy item at -1 without changing the dataprovider (I really hate adding "No one" to the original employeeList dataprovider)

P/S: same questions but still no answer:

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

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

发布评论

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

评论(5

绅刃 2024-11-12 03:20:25

我建议通过创建一个名为“DummyArrayCollection”的类来扩展 ArrayCollection 类。您可以将虚拟变量存储在那里并将其用作数据提供者,而不会影响原始员工列表:

public class DummyArrayCollection extends ArrayCollection
{
    private var _firstElement:String;
    private var _dummyArray:Array;

    public function DummyArrayCollection(source:Array=null)
    {
        super(source);
        _dummyArray = init(source);
        _firstElement = "";
    }

    public function init(src:Array):Array{
        var retArr:Array = new Array();
        retArr[0] = _firstElement; //add your dummy element here
        for(var i:int=0;i<src.length;i++){
            retArr[i] = src[i];
        }
        return retArr;
    }
}

I would recommend extending the ArrayCollection class by creating a class called "DummyArrayCollection." You can store your dummy variable there and use this as a dataprovider without affecting the original list of employees:

public class DummyArrayCollection extends ArrayCollection
{
    private var _firstElement:String;
    private var _dummyArray:Array;

    public function DummyArrayCollection(source:Array=null)
    {
        super(source);
        _dummyArray = init(source);
        _firstElement = "";
    }

    public function init(src:Array):Array{
        var retArr:Array = new Array();
        retArr[0] = _firstElement; //add your dummy element here
        for(var i:int=0;i<src.length;i++){
            retArr[i] = src[i];
        }
        return retArr;
    }
}
花开柳相依 2024-11-12 03:20:25

将更改事件处理程序添加到下拉列表中:

change = "{myDropDown.selectedIndex = -1}"

这样,您的提示将在选择项目后重复使用。

Add a change event handler to your drop down list:

change = "{myDropDown.selectedIndex = -1}"

this way your prompt will be reused after item was selected.

乜一 2024-11-12 03:20:25

以防万一有人感兴趣,我刚刚发现了这个:

收据

Just in case somebody was interested I had just found this:

Receipt

季末如歌 2024-11-12 03:20:25

这是一个工作的 Flex 3 示例。我确信它可以很容易地转换为 flex 4。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init( )" width="100%" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.collections.XMLListCollection;

            [Bindable]
            public var personsList:XMLListCollection;

            private function init( ):void{

                var xml:XML = 
                <root>
                    <persons>
                        <person><label>jim</label><value>jim</value></person>
                        <person><label>joe</label><value>joe</value></person>
                        <person><label>bob</label><value>bob</value></person>
                        <person><label>harry</label><value>harry</value></person>
                        <person><label>sally</label><value>sally</value></person>
                    </persons>
                </root>;

                this.personsList =  new XMLListCollection( xml.persons.person )

                var myFirstNodeXML:XML = <person><label>None Selected</label><value>none</value></person>;
                this.personsList.addItemAt(myFirstNodeXML,0);
                myCB.selectedIndex = 0;
            }

        ]]> 
    </mx:Script>
    <mx:ComboBox id="myCB" dataProvider="{this.personsList}"/>
</mx:Application>

Here is a working flex 3 example. I am sure it can be converted to flex 4 easy enough.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init( )" width="100%" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.collections.XMLListCollection;

            [Bindable]
            public var personsList:XMLListCollection;

            private function init( ):void{

                var xml:XML = 
                <root>
                    <persons>
                        <person><label>jim</label><value>jim</value></person>
                        <person><label>joe</label><value>joe</value></person>
                        <person><label>bob</label><value>bob</value></person>
                        <person><label>harry</label><value>harry</value></person>
                        <person><label>sally</label><value>sally</value></person>
                    </persons>
                </root>;

                this.personsList =  new XMLListCollection( xml.persons.person )

                var myFirstNodeXML:XML = <person><label>None Selected</label><value>none</value></person>;
                this.personsList.addItemAt(myFirstNodeXML,0);
                myCB.selectedIndex = 0;
            }

        ]]> 
    </mx:Script>
    <mx:ComboBox id="myCB" dataProvider="{this.personsList}"/>
</mx:Application>
烙印 2024-11-12 03:20:25

dropDownList.selectedItem=null

dropDownList.selectedItem=null

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