在 Flex 中使用可变数量的列和行填充数据网格
我试图找出如何基于这样的 XML 对象来管理 Datagrid:
<matrix rows="5" columns="5">
<column>
<row>0.5</row>
<row>0.21</row>
</column>
<column>
<row>0.6</row>
<row>0.9</row>
</column>
<column>
<row>0.5</row>
<row>0.5</row>
</column>
<column>
<row>0.8</row>
<row>0.4</row>
</column>
</matrix>
我需要根据不同的 XML 对象填充 Datagrid 列名称,并使用上面的 XML 来填充每个列的行。我目前能够创建数据网格并填充其列标题,但我不确定如何为每列添加行。上面的 XML 将随着添加和删除的新行和列元素进行更新。当然,这将绑定到数据网格以显示更新。
I am trying to figure out how to manage a Datagrid based on an XML object like this:
<matrix rows="5" columns="5">
<column>
<row>0.5</row>
<row>0.21</row>
</column>
<column>
<row>0.6</row>
<row>0.9</row>
</column>
<column>
<row>0.5</row>
<row>0.5</row>
</column>
<column>
<row>0.8</row>
<row>0.4</row>
</column>
</matrix>
I will need to populate the Datagrid column names based on a different XML object and use the above XML to populate each of the column's rows. I currently am able to create the Datagrid and populate its column headers but I am unsure as to how to how to add the rows for each column. The above XML will be update with new row and column elements added and deleted. This, of course, will be bound to the Datagrid to show updates.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
行数据一定是列的子数据吗?如果是这种情况,您需要先转换数据。 Flex 中的 DataGrid 和 HTML 中的 Table 都基于数据库的约定,其中行作为单独的记录,而不是列。
如果提供数据的人/任何东西拒绝遵守这一点,那么您最好操纵数据以适应视图控件,而不是反之亦然,这就是您现在似乎正在做的事情。
Is it necessarily true that the row data is child of the column? You will need to transform the data first if this is the case. DataGrid in Flex and Table in HTML are based on the convention of databases with rows as individual records, not columns.
If whom/whatever is providing the data refuses to comply with this, you'd be better to manipulate the data to suit the view control rather than vice versa, which is what you seem to be doing now.
数据网格的行将是动态的。它将根据数据提供者中的项目数量进行填充。但要使列动态化,您必须使用 AS 来完成。
数据网格有一个称为“列”的属性。其中包含该数据网格的 DataGridColumn 对象。您可以检查数据提供程序并向“列”数组添加或删除 DatagridColumns。
The rows of a datagrid will be dynamic. It will be populated based on the number of items in the data provider. But to make columns dynamic you have to do it using AS.
Datagrid has a property called "columns". this contains the DataGridColumn objects for that datagrid. You can check the dataprovider and add or remove DatagridColumns to the "columns" Array.