在 Flex 4 中通过动作脚本选择 DropDownList 的值
我确信这很简单,但我一直在寻找如何使用动作脚本选择 DropDownList 元素。在这种情况下,我希望能够基于 ddlLabel 或 ddlData 指定 selectedItem
<?xml version="1.0" encoding="utf-8"?>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
protected var timezonesArray:ArrayCollection = new ArrayCollection([
{ddlLabel:"Eastern Time", ddlData:"EST"},
{ddlLabel:"Central Time", ddlData:"CST"},
{ddlLabel:"Mountain Time", ddlData:"MST"},
{ddlLabel:"Pacific Time", ddlData:"PST"}
]);
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
// I'm looking to select an element via actionscript here, based on ddlLabel or ddlData
}
]]>
</fx:Script>
<mx:Form>
<s:DropDownList id="ddlTimezones" dataProvider="{timezonesArray}" labelField="ddlLabel"/>
</mx:Form>
I'm sure this is a easy one but I've been searching for a while how to select a DropDownList element with actionscript. In this scenario, I'd like to be able to specify the selectedItem based either on ddlLabel or ddlData
<?xml version="1.0" encoding="utf-8"?>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
[Bindable]
protected var timezonesArray:ArrayCollection = new ArrayCollection([
{ddlLabel:"Eastern Time", ddlData:"EST"},
{ddlLabel:"Central Time", ddlData:"CST"},
{ddlLabel:"Mountain Time", ddlData:"MST"},
{ddlLabel:"Pacific Time", ddlData:"PST"}
]);
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
// I'm looking to select an element via actionscript here, based on ddlLabel or ddlData
}
]]>
</fx:Script>
<mx:Form>
<s:DropDownList id="ddlTimezones" dataProvider="{timezonesArray}" labelField="ddlLabel"/>
</mx:Form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法可以做到这一点 - 如果您需要使用标签或值来执行此操作,您可以像这样循环遍历数组集合:
但是,如果您单独保留对时区的引用或者从以下位置获取它们在应用程序的其他部分,您可以做得更干净:
这样,您不必担心询问列表中的每个对象,因为您停留在整个对象的级别而不是触及它们。如果您想用类定义替换 JSON 样式对象列表,如果您开始需要存储有关时区的更复杂的信息,它也会变得更容易。
There are a couple ways to do this - if you need to do it using the label or the value, you can loop though the arraycollection like this:
However, if you keep a reference to the time zones individually or you're getting them from some other part of the app, you can do it more cleanly:
This way, you don't have to worry about interrogating every object in the list, because you're staying at the level of whole objects rather than reaching into them. It also makes it easier if you want to replace your list of JSON style objects with a class definition, if you start needing to store more complicated information about time zones.