How to convert Array 2D to Array collection in Flex
i have 2d array follows:
asia india chennai tn category1 product1 100 asia india mumbai mh category1 product1 100 asia india calcutta ct category1 product1 100 asia india calcutta ct category2 product2 200 emea uk london ln category3 product1 123 emea uk london ln category3 product2 455 emea uk reading rn category1 product1 500 emea uk reading rn category1 product2 430
how can convert above 2d array array collection i can access each data individual attribute first column to indicate attribute "continent",2nd column "country" etc ., arraycollection haveing structure {continent:"asia", country:"india",...etc} , on.how achieve dynamically.
hi rohini_1327,
your question not clear. since refer 2d array, take mean have array of arrays, such that:
myarray:array = [("asia", "india", "chennai", "tn", "category1", "product1", 100),
("asia", "india", "mumbai", "mh", "category1", "product1", 100),
("asia", "india", "calcutta", "ct", "category1", "product1", 100),
("asia", "india", "calcutta", "ct", "category2", "product2", 200),
("emea", "uk", "london", "ln", "category3", "product1", 123),
("emea", "uk", "london", "ln", "category3", "product2", 455),
("emea", "uk", "reading", "rn", "category1", "product1", 500),
("emea", "uk", "reading", "rn", "category1", "product2", 430)];
if so, since know category names , nice , neat:
var types:array = ["continent", "country", "city", "abbr", "cat1", "prod1", "qty"]; // array of names columns
var myarraycollection:arraycollection = new arraycollection;
for each(var arr:array in myarray) // iterate through each elment of 2d array
{
var temp:object = new object; // temporary holder our arraycollection items
for(var i:int = 0; < 7; i++) // iterate through each sub-array
{
temp[types(i)] = arr(i);
}
myarraycollection.additem(temp);
}
now: myarraycollection[0].continent = "asia"
or: var obj:object = myarraycollection.getitemat(3);
obj.city = "calcutta"
you have iterate through list. in case, 2d array, have 2 nested iterations. if each array element of myarray array, add iteration function.
see http://help.adobe.com/en_us/as3/dev/ws5b3ccc516d4fbf351e63e3d118a9b90204-7fdc.html more information.
More discussions in Flex (Read Only)
adobe
Comments
Post a Comment