Expand my Community achievements bar.

Access Child Objects in AS Object from FDS

Avatar

Level 2
I have a dataservice setup to fill an arraycollection of
Teacher objects. Each Teacher object has a School object. These
appear to be properly returned from FDS as strongly-typed objects.
In the debugger, I can see my arraycollection of Teacher objects
and I can see valid School objects nested inside each one. However,
when I tried to display the data in a datagrid, I cannot get the
properties of the School object nested in the Teacher object to
print out. Here is what I'm trying to do:



<mx:DataGrid id="teachers_datagrid" editable="true"
dataProvider="{teachersArray}">

<mx:columns>

<mx:DataGridColumn dataField="teacherid"
headerText="Teacher Id" editable="false"/>

<mx:DataGridColumn dataField="teachername"
headerText="Teacher Name"/>

<mx:DataGridColumn dataField="school.schoolid"
headerText="School Id"/>

<mx:DataGridColumn dataField="school.schoolname"
headerText="School Name"/>

</mx:columns>

</mx:DataGrid>



For some reason, the school.schoolid and school.schoolname
values will not show up, while the teacherid and teachername appear
correctly. If I just put 'school', I can see the value of the
object represented as a string (ie [Object]). When I look in the
debugger, I see what appears to be a correct arraycollection of
Teachers with valid School properties inside them. Is there some
other way to display the child properties that are complex
objects?
2 Replies

Avatar

Level 2
Bill,



You cannot reference nested object properties directly in a
datagrid. For example, datafield="teacherid" is ok but
datafield="school.schoolid" is not. To reference nested object
properties you need to set up a labelFunction (see the
DataGridColumn documentation). In the labelFunction you can
reference the desired property like this example:



// paints the unit of measure for the school id

public function resourceSchoolIDLabel( data : Object, column
: DataGridColumn ) : String {

return data.school.schoolid;

}