使用逗号分隔的多个值填充 dataGrid 中的单元格 - Flex

发布于 2024-11-17 15:42:57 字数 2890 浏览 1 评论 0原文

我有一个包含此数据的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

画尸师 2024-11-24 15:42:57

您必须编写一个 labelFunction 来返回要在列中显示的逗号分隔列表。

阅读有关创建自定义标签函数的文档。以下是一些相关详细信息:

[Start Quote]

您可以将标签函数传递给 List 控件,以提供确定控件中显示的文本的逻辑。 label 函数必须具有以下签名:

labelFunction(item:Object):String

Label 控件传入的 item 参数包含列表项对象。该函数必须返回要在列表控件中显示的字符串。

注意:ListBase 的大多数子类也采用带有上述签名的 labelFunction 属性。对于 DataGrid 和 DataGridColumn 控件,方法签名为 labelFunction(item:Object, dataField:DataGridColumn):String,其中 item 包含 DataGrid 项对象,dataField 指定 DataGrid 列。

....

<mx:Script><![CDATA[
    public function myLabelFunc(item:Object):String {
        return item.data + ", " + item.label; 
    }
]]></mx:Script>

[引用结束]

item 对象参数是您要为其生成标签的 dataProvider 的元素。

您可以在相关类上指定 labelFunction 属性:

<mx:DataGridColumn labelFunction="myLabelFunc" />

您还可以使用自定义 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:

labelFunction(item:Object):String

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.

....

<mx:Script><![CDATA[
    public function myLabelFunc(item:Object):String {
        return item.data + ", " + item.label; 
    }
]]></mx:Script>

[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:

<mx:DataGridColumn labelFunction="myLabelFunc" />

You can also do the same thing with a custom itemRenderer.

一生独一 2024-11-24 15:42:57

这就是我要做的:

  1. 为 DataGrid 中的 Subclasses 列创建一个自定义 itemRenderer。
  2. 重写 set data 方法以遍历所有子类并构建逗号分隔的字符串。
  3. 将 itemRenderer 标签的值设置为逗号分隔的字符串。

Here's what I would do:

  1. Make a custom itemRenderer for the Subclasses column in the DataGrid.
  2. Override the set data method to go through all of your subclasses and build the comma delimited string.
  3. Set the value of the itemRenderer's label to your comma delimited string.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文