开发者

Assign an Array element to Another Array

Hello I have this array:

private var all_array:Array = [
    { symbol: "ADBE", name: "Adobe Systems Inc.", price: 49.95 },
    { symbol: "MACR", name: "Macromedia Inc.", price: 39.95 },
    { symbol: "MSFT", name: "Microsoft开发者_JS百科 Corp.", price: 25.95 },
    { symbol: "IBM", name: "IBM Corp.", price: 42.55 }
    ];

I want another array which takes the values of the price from the 1st Array. Can we do something like this?

private var another_price_array:Array = [all_array.price];

This second array will be used to populate a ComboBox, or can I populate the combo directly from the first array itself?

Thanks

Thx


MX ComboBox:

<mx:ComboBox dataProvider="{all_array}" labelField="price" />

Spark ComboBox:

<s:ComboBox = dataProvider="{new ArrayCollection(all_array)}" labelField="price" />

To use this code without changes make sure your all_array is bindable.


Why not populate the ComboBox directly w/ the First array? You will need to turn it into an ArrayList or ArrayCollection if you're using Spark components, though:

Do something like this to turn your array into an ArrayCollection:

private var myCollection = new ARrayCollection(all_Array);

and set it as the dataProvider, specifying the labelField to display your price data in the drop down of the ComboBox:

<s:ComboBox dataProvider="{myCollection}" labelField="price" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜