简体   繁体   中英

Flex Datagrid and finding number member variable of a class

i have two questions

  1. 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.

  2. 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:

  1. Using a for..in loop. This only works for dynamically added properties.
  2. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM