使用逗号分隔的多个值填充 dataGrid 中的单元格 - Flex
我有一个包含此数据的 XML 文件。
<resultSet>
<MerchandiseAssortmentCategory>
<merchandiseAssortmentCategoryId>275</merchandiseAssortmentCategoryId>
<merchandiseAssortmentCategoryName>D21 Plywood</merchandiseAssortmentCategoryName>
<merchandiseSubordinateClasses>
<merchandiseSubordinateClass>
<merchandiseSubordinateClassNumber>2</merchandiseSubordinateClassNumber>
<merchandiseSubordinateClassDescription>SHEATHING</merchandiseSubordinateClassDescription>
</merchandiseSubordinateClass>
<merchandiseSubordinateClass>
<merchandiseSubordinateClassNumber>3</merchandiseSubordinateClassNumber>
<merchandiseSubordinateClassDescription>WAFERBOARD</merchandiseSubordinateClassDescription>
</merchandiseSubordinateClass>
<merchandiseSubordinateClass>
<merchandiseSubordinateClassNumber>4</merchandiseSubordinateClassNumber>
<merchandiseSubordinateClassDescription>SANDED</merchandiseSubordinateClassDescription>
</merchandiseSubordinateClass>
</merchandiseSubordinateClasses>
</MerchandiseAssortmentCategory>
</resultSet>
我需要使用同一行中的商品AssortmentCategoryName 及其所有以逗号分隔的商品SubordinalClassNumber 填充数据网格。
categoryList 是 dataGrid 的数据提供者,定义如下:
this.categoryList= evt.result.resultSet.MerchandiseAssortmentCategory;
这就是 dataGrid 的定义方式
<mx:DataGrid x="466" y="73" width="192" height="225"
dataProvider="{categoryList}"
verticalScrollPolicy="on"
id="categories"
rowCount="10" enabled="true">
<mx:columns>
<mx:DataGridColumn headerText="Category name" dataField="merchandiseAssortmentCategoryName"/>
<mx:DataGridColumn headerText="Subclasses" dataField="merchandiseSubordinateClasses.merchandiseSubordinateClass.merchandiseSubordinateClassNumber"/>
</mx:columns>
</mx:DataGrid>
当我运行此命令时,仅填充类别名称。下级编号为空。帮忙解决一下这个问题。谢谢
I have an XML file with this data.
<resultSet>
<MerchandiseAssortmentCategory>
<merchandiseAssortmentCategoryId>275</merchandiseAssortmentCategoryId>
<merchandiseAssortmentCategoryName>D21 Plywood</merchandiseAssortmentCategoryName>
<merchandiseSubordinateClasses>
<merchandiseSubordinateClass>
<merchandiseSubordinateClassNumber>2</merchandiseSubordinateClassNumber>
<merchandiseSubordinateClassDescription>SHEATHING</merchandiseSubordinateClassDescription>
</merchandiseSubordinateClass>
<merchandiseSubordinateClass>
<merchandiseSubordinateClassNumber>3</merchandiseSubordinateClassNumber>
<merchandiseSubordinateClassDescription>WAFERBOARD</merchandiseSubordinateClassDescription>
</merchandiseSubordinateClass>
<merchandiseSubordinateClass>
<merchandiseSubordinateClassNumber>4</merchandiseSubordinateClassNumber>
<merchandiseSubordinateClassDescription>SANDED</merchandiseSubordinateClassDescription>
</merchandiseSubordinateClass>
</merchandiseSubordinateClasses>
</MerchandiseAssortmentCategory>
</resultSet>
I need to populate a data grid with the merchandiseAssortmentCategoryName and all its merchandiseSubordinateClassNumber(s) seperated with commas in the same row.
the categoryList is which is the dataprovider for the dataGrid is defined as follows :
this.categoryList= evt.result.resultSet.MerchandiseAssortmentCategory;
and this is how the dataGrid is defined
<mx:DataGrid x="466" y="73" width="192" height="225"
dataProvider="{categoryList}"
verticalScrollPolicy="on"
id="categories"
rowCount="10" enabled="true">
<mx:columns>
<mx:DataGridColumn headerText="Category name" dataField="merchandiseAssortmentCategoryName"/>
<mx:DataGridColumn headerText="Subclasses" dataField="merchandiseSubordinateClasses.merchandiseSubordinateClass.merchandiseSubordinateClassNumber"/>
</mx:columns>
</mx:DataGrid>
When i run this, only the category name is filled. the subordinateclass number is just blank. Help out with this. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须编写一个 labelFunction 来返回要在列中显示的逗号分隔列表。
阅读有关创建自定义标签函数的文档。以下是一些相关详细信息:
[Start Quote]
您可以将标签函数传递给 List 控件,以提供确定控件中显示的文本的逻辑。 label 函数必须具有以下签名:
Label 控件传入的 item 参数包含列表项对象。该函数必须返回要在列表控件中显示的字符串。
注意:ListBase 的大多数子类也采用带有上述签名的 labelFunction 属性。对于 DataGrid 和 DataGridColumn 控件,方法签名为 labelFunction(item:Object, dataField:DataGridColumn):String,其中 item 包含 DataGrid 项对象,dataField 指定 DataGrid 列。
....
[引用结束]
item 对象参数是您要为其生成标签的 dataProvider 的元素。
您可以在相关类上指定 labelFunction 属性:
您还可以使用自定义 itemRenderer 执行相同的操作。
You're going to have to write a labelFunction to return the comma separated list you want displayed in the column.
Read these docs on creating a custom label function. Here are some relevant details:
[Start Quote]
You can pass a label function to the List control to provide logic that determines the text that appears in the control. The label function must have the following signature:
The item parameter passed in by the Label control contains the list item object. The function must return the string to display in the List control.
Note: Most subclasses of ListBase also take a labelFunction property with the signature described above. For the DataGrid and DataGridColumn controls, the method signature is labelFunction(item:Object, dataField:DataGridColumn):String, where item contains the DataGrid item object, and dataField specifies the DataGrid column.
....
[End Quote]
The item object parameter is the element of the dataProvider you want to generate a label for.
You can specify the labelFunction property on the class in question:
You can also do the same thing with a custom itemRenderer.
这就是我要做的:
set data
方法以遍历所有子类并构建逗号分隔的字符串。Here's what I would do:
set data
method to go through all of your subclasses and build the comma delimited string.