Flex 在 IndexChangeEvent 处理程序之外的 Spark 列表中设置 selectedItem
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过这样做:
请参阅此处:
如何确保 Spark 列表中始终有选定的内容?
Have you tried doing this:
see here:
How do I make sure that there is always something selected in a Spark List?