gpt4 book ai didi

apache-flex - 通过 Flex 4 中的 ActionScript 选择 DropDownList 的值

转载 作者:行者123 更新时间:2023-12-04 06:32:30 28 4
gpt4 key购买 nike

我确信这是一个简单的方法,但我一直在寻找如何使用 actionscript 选择 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>

最佳答案

有几种方法可以做到这一点 - 如果你需要使用标签或值来做到这一点,你可以像这样循环遍历 arraycollection:

protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
var searchTerm:String = "EST";
var result:* = null;
for each(var zone:* in timeZonesArray)
{
if(searchTerm == zone.ddlData)
{
result = zone;
break;
}
}
ddlTimezones.selectedItem = result;
}

但是,如果您单独保留对时区的引用,或者从应用程序的其他部分获取时区,则可以更简洁地进行:
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;


var EST:Object = {ddlLabel:"Eastern Time", ddlData:"EST"};
var CST:Object = {ddlLabel:"Central Time", ddlData:"CST"};
var MST:Object = {ddlLabel:"Mountain Time", ddlData:"MST"};
var PST:Object = {ddlLabel:"Pacific Time", ddlData:"PST"};

[Bindable]
protected var timezonesArray:ArrayCollection = new ArrayCollection([
EST,
CST,
MST,
PST
]);

protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
ddlTimezones.selectedItem = EST;
}

这样,您不必担心询问列表中的每个对象,因为您停留在整个对象的级别而不是进入它们。如果您想用类定义替换 JSON 样式对象列表,如果您开始需要存储有关时区的更复杂的信息,它也会更容易。

关于apache-flex - 通过 Flex 4 中的 ActionScript 选择 DropDownList 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5235098/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com