I don't know anything about fluorine, but based on the object, I'd
programmatically set up the DG
All the formatting got lost in the email, so I might be off a bit, but
I'd do something like this:
var fieldMap:Object = new Object();
var cols:Array = new Array();
var n:int = columnNames.length;
var i:int;
for (i = 0; i < n; i++)
{
// map filed names to array indices
fieldMap[columnNames[i]] = i.toString();
var dgc:DataGridColumn = new DataGridColumn();
dgc.headerText = columnNames[i];
dgc.dataField = i.toString();
cols.push(dgc);
}
grdPERSONResults.columns = cols;
grdPERSONResults.dataProvider = initialData;
You can access the fields of the data objects like this:
trace(initialData[i][fieldMap["PERSON_NUMBER"]);
If you do that, you can handle any result type.
If you know the fields you are going to get, you can use a similar loop
to convert to object. Declare a class:
Class PERSON
{
Public var PERSON_NUMBER:int;
Public var PERSON_NAME:String;
...
}
var n:int = columnNames.length;
Var persons:Array = new Array;
var m:int = initialData.length;
for (i = 0; i < m; i++)
{
Var person:Person = new PERSON();
For (var j:int = 0; j < n; j++)
{
person[columnNames[j]] = initialData[i][j];
}
}
grdPERSONResults.dataProivder = persons;
________________________________
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of aceoohay
Sent: Saturday, October 27, 2007 1:41 PM
To: [email protected]
Subject: [flexcoders] Re: How do I convert an object to an
arrayCollection?
Yes you can, but this does not allow the ability to access the fields
in the data provider by name.
In my existing programs I might have something like;
================================================================
<mx:DataGrid x="10" y="64" width="599" height="424"
id="grdPERSONResults"
itemClick="grdPERSONSelected(event);" >
<mx:columns>
<mx:DataGridColumn headerText="Number" textAlign="right"
width="60" dataField="PERSON_NUMBER"/>
<mx:DataGridColumn headerText="Name" width="200"
dataField="PERSON_NAME"/>
<mx:DataGridColumn headerText="Original #" textAlign="right"
width="65" dataField="PERSON_ORIG_NUMBER"/>
<mx:DataGridColumn headerText="SSN" labelFunction="SSNFormat"
width="85" dataField="PERSON_SSN"/>
<mx:DataGridColumn headerText="Date" labelFunction="showDate"
textAlign="center" width="80" dataField="PERSON_DATE"/>
<mx:DataGridColumn headerText="Status" textAlign="center"
width="50" dataField="PERSON_PERSON_STATUS"/>
</mx:columns>
</mx:DataGrid>
================================================================
And I would like to convert it to Fluorine with as little change as
possible.
Paul
--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> You can pass an array to the datagrid's dp
>
>
>
> ________________________________
>