Flex DataGird动态列问题
正常情况下,使用datagird绑定一个arraycolltetion的时候,需要进行如下代码
<mx:DataGrid x="10" y="20" dataProvider="{employees}"> <mx:columns> <mx:DataGridColumn dataField="name" headerText="Name"/> <mx:DataGridColumn dataField="phone" headerText="Phone"/> <mx:DataGridColumn dataField="email" headerText="Email"/> </mx:columns> </mx:DataGrid>
]<mx:DataGrid x="10" y="20" dataProvider="{employees}"/>
import mx.utils.ObjectUtil;var record:Object = dataStore.getItemAt(0);var classinfo:Object = ObjectUtil.getClassInfo(record);var columns:Array = [];var column:DataGridColumn = null;for each (var p:* in classinfo.properties){ column = new DataGridColumn(); column.dataField = p;// 这个p就是里面的属性名 column.headerText = p; columns.push(column);}