Flex 在 IndexChangeEvent 处理程序之外的 Spark 列表中设置 selectedItem

发布于 2024-12-27 20:11:03 字数 1426 浏览 0 评论 0原文

我有一个 Spark 列表,它是 CallOutContent 的一部分,很像这样:

<s:CalloutButton id="frequencyChanger" label="{frequencyChangeList.selectedItem.label}">
    <s:calloutContent>
        <s:BorderContainer>
             <s:layout>
                  <s:VerticalLayout/>
             </s:layout>
             <s:List id="frequencyChangeList" dataProvider="{Util.getFrequencyList()}" selectedIndex="8" requireSelection="false"                           changing="frequencyList_changingEvent(event)"/>
        </s:BorderContainer>
    </s:calloutContent>
</s:CalloutButton>

dataProvider 是一个 ArrayList,其中包含以下结构的多个项目:

public class ListItem
{
    public var label:String;
    public var item:Object;

    public function PeriodFrequencyListItem(label:String, item:Object) { 
        this.label=label;
        this.item=item;
    }
}

项目对象是一个枚举。 其背景是将枚举与要在列表中显示的相应标签相匹配。我本来会使用字典,但列表不起作用(不幸的是)。

无论如何,在 IndexChangeEvent 方法中,我可以将 selectedItem 设置为当前选定的项: FrequencyChangeList.selectedItem = event.currentTarget.selectedItem;

我不能做的(但在类的另一部分迫切需要)是在 IndexChangeEvent 方法之外设置列表的 selectedItem 。 任何使用类似以下内容设置项目的尝试都会失败,并引发空指针异常。

frequencyChangeList.selectedItem = someListItemObject;

我可以设置 CallOutButtons 的标签,当然,这不会改变列表的选择。 那么,除了自己的“更改”方法之外,在列表中选择一个项目的技巧在哪里呢?

任何帮助将不胜感激。 干杯!

I've got a spark list that is part of a CallOutContent, much like this:

<s:CalloutButton id="frequencyChanger" label="{frequencyChangeList.selectedItem.label}">
    <s:calloutContent>
        <s:BorderContainer>
             <s:layout>
                  <s:VerticalLayout/>
             </s:layout>
             <s:List id="frequencyChangeList" dataProvider="{Util.getFrequencyList()}" selectedIndex="8" requireSelection="false"                           changing="frequencyList_changingEvent(event)"/>
        </s:BorderContainer>
    </s:calloutContent>
</s:CalloutButton>

The dataProvider is an ArrayList with several items of the following structure:

public class ListItem
{
    public var label:String;
    public var item:Object;

    public function PeriodFrequencyListItem(label:String, item:Object) { 
        this.label=label;
        this.item=item;
    }
}

The item Object is an Enum.
Background for this is to match the Enum to the corresponding label to be displayed in the List. I would have used a dictionary, but Lists don't work this those (unfortunately).

Anyhow, in the IndexChangeEvent method I can set the selectedItem to the one currently selected:
frequencyChangeList.selectedItem = event.currentTarget.selectedItem;

What I can't do (but desperately need in another part of the class) is to set the selectedItem of the List outside of the IndexChangeEvent method.
Any attempt to set an item with something like the following failed, throwing a null pointer exception.

frequencyChangeList.selectedItem = someListItemObject;

I can set the labels of the CallOutButtons, naturally, that doesn't change the selection of the List.
So, where is the trick to select an item in the list outside of its own 'changing' method?

Any help would be much appreciated.
Cheers!

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

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

发布评论

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

评论(1

雨后咖啡店 2025-01-03 20:11:03

您是否尝试过这样做:

myList.selectedIndex = indexOfArray;

请参阅此处:

如何确保 Spark 列表中始终有选定的内容?

Have you tried doing this:

myList.selectedIndex = indexOfArray;

see here:

How do I make sure that there is always something selected in a Spark List?

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