Flex Datagrid and finding number member variable of a class
i have two que开发者_如何学JAVAstions
How to populate a flex datagrid from an Arraycollection without specifying DataGridColumn's individually. Is there any custom datagrid available where I can pass the datasource arraycollection and see the data populated in the output.
Without knowing the structure / bluprint of an object is there anyway to find how many member variable that class have?
With respect to your second question - there are 2 ways to accomplish this:
- Using a for..in loop. This only works for dynamically added properties.
- Using the describeType API. This will return a rich XML object describing an object, including all of its member variables as well as their visibility.
You can read more about these two techniques here.
static public function getDetails(argData:Object , grid:DataGrid):void {
// Get the Button control's E4X XML object description.
var classInfo:XML = describeType(argData);
// List accessors as properties.
var _columnList:Array = new Array();
for each (var a:XML in classInfo..accessor) {
// Do not get the property value if it is write only.
var _column:DataGridColumn = new DataGridColumn;
// Setting properties
_column.headerText = a.@name;
_column.dataField = a.@name;
_column.width = 180;
_columnList.push(_column);
}
grid.columns = _columnList;
}
Populated Datagrid through this routine , helps a lot debugging my result data.
精彩评论