Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Retrieve information from arrayCollection

Avatar

Level 1

Hi everyone,

i have a very simple problem, but i'm a new flex developper and i have no clue of what to do.

i've retrieved information from a database using a webservice in coldfusion.

in flex i retrieved the result of my query into a arrayCollection

private var tabInfosDriver:ArrayCollection

private function driverInfoHandler(event:ResultEvent):void

tabInfosDriver=event.result as ArrayCollection;

and if i give {tabInfosDriver} as dataprovider to some datagrid, the query result is shown properly, something like that.

Header1Header2Header3Header4Header5
someValuesomeValue2someValue3someValue4someValue5


now i want to use someValue from header1 to populate a textField for example.

i tried :

label1.text = tabInfosDriver.getItemAt(1,0).toString()

but it errored : index array out of bounds, and anyway i want to use the name of the header field, wich is the one of the database table to call it's value

label1.text = tabInfosDriver.getItemAt("header1").value.toString()

what can i do ? i'm sure this is easy to solve. i have looked all the methods from the arrayCollection object, but i can't figure wich one to use.

please forgive me for my language, i do not speak english very often.

dominic

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Often it is possible to either return data to the Flex app in standard object notation, or to reconfigure the data that way after it comes back to the Flex app in the result handler. The standard notation I'm referring to is:

{

    {key1: "value 1", key2: "value2", key3: "value3"},

    {key1: "value 1", key2: "value2", key3: "value3"},

    {key1: "value 1", key2: "value2", key3: "value3"},

    {key1: "value 1", key2: "value2", key3: "value3"}

}

So in this way the data is already structured as an associative array, because such an array is really just an ActionScript object.

So the above data should be accessible in two ways:

var tempVar:String = myObject.key1;

var tempVar:String = myObject[key1];    (might be myObject["key1"])

Incidentally, that "standard object notation" is also known as JSON, and there are libraries out there for handling JSON formatted data in Flex, PHP, etc. though you don't necessarily have to process it as JSON, that just makes it a bit more formal, and provides some additional APIs:

http://code.google.com/p/as3corelib/

View solution in original post

6 Replies

Avatar

Former Community Member

I do not fully understand exactly you are trying to do, but anyway getItemAt(1,0) won't work, do you mean getItemAt(1) or getItemAt(0)?

Each column in the datagrid has a property headerText, so you might be able to use that somehow.

Like I said, I'm not exactly sure what you want to do, please describe again.

If this post answered your question or helped, please mark it as such.

Avatar

Level 1

ok,     thanks for answering, i'll try to be more clear.

the getItemAt(n) doesn't intersest me. the index is no use for me because i don't know wich index refers to what.

I need to retrieve the data from the arrayCollection knowing the name of the column (wich contains only one value).

so, yes your idea of using the header text property is interesting, but not onto a datagrid but directly on the arrayCollection.

in java, i would ask to retrieve the value from it's key, wich key would of been setted when building the array. And I do suppose that you can do this also with an flex arrayCollection

i hope this helps you help me, cause i'm blocked here.

thank you again.

dominic

Avatar

Level 1

Ok, associative arrays are what i need. I looked documentation and indeed it's what i'm describing.

my problem isn't solve though, for i am not the one building the array. the array is built by sql server. then returned to the flex program whom

parses it into a arrayCollection so it can use the information. so, unless i can build an associativeArray dynamically with the headers of my sql query columns (into the arrayCollection) as the keys, i can't use the associativeArray. and, if i can build one with the column names as  keys, there is surely a way to extract them otherwise.

i've been thinking of another way to extract my data.

if the output of the datagrid containing my query shows the way my arrayCollection is built, i mean if the first column in the datagrid is for example header1 and  myArrayCollection.getItemAt(1) = header1, there is a relation that with a little bit of code i can handle.

though the output of the datagrid seems to be done alphabetically, wich means it is no use for me.

if you can tell me what you think about these two ideas, i would be very glad. and i'd continue giving you points.

thank you Greg

dominic

Avatar

Level 1

also, i've just thought that i'm the one in charge of the sql query so if giving aliases to my columns could be of any help

or if any solution could come from the sql query, please inform me.

dominic

Avatar

Correct answer by
Former Community Member

Often it is possible to either return data to the Flex app in standard object notation, or to reconfigure the data that way after it comes back to the Flex app in the result handler. The standard notation I'm referring to is:

{

    {key1: "value 1", key2: "value2", key3: "value3"},

    {key1: "value 1", key2: "value2", key3: "value3"},

    {key1: "value 1", key2: "value2", key3: "value3"},

    {key1: "value 1", key2: "value2", key3: "value3"}

}

So in this way the data is already structured as an associative array, because such an array is really just an ActionScript object.

So the above data should be accessible in two ways:

var tempVar:String = myObject.key1;

var tempVar:String = myObject[key1];    (might be myObject["key1"])

Incidentally, that "standard object notation" is also known as JSON, and there are libraries out there for handling JSON formatted data in Flex, PHP, etc. though you don't necessarily have to process it as JSON, that just makes it a bit more formal, and provides some additional APIs:

http://code.google.com/p/as3corelib/

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----