【问题标题】:Displaying properties from two objects in a datagrid在数据网格中显示两个对象的属性
【发布时间】:2009-12-11 05:22:48
【问题描述】:

之前我在 Flex Adob​​e 论坛上发布了关于此问题的讨论,但仍然不明白需要做什么。所以,我会在 stackoverflow 上再试试运气。

我在数据网格上使用 Flash Builder 4 中的拖放数据绑定功能。但是,我需要显示的数据需要从另一个对象中查询。

<mx:DataGrid id="dataGrid2" dataProvider="{getMajorDetailsResult.lastResult}"> <mx:columns> <mx:DataGridColumn headerText="Category Name" /> <mx:DataGridColumn headerText="Require Credits" dataField="requireCredits" resizable="false" width="40"/> </mx:columns> </mx:DataGrid>

在这个数据网格中,我将它与一个对象 MACL 绑定,该对象具有

  • 身份证
  • CAT_ID
  • 需要积分

但是,我想在第一列显示 CategoryName 但 categoryName 在另一个对象(类别)中

  • CAT_ID
  • 类别名称

在这种情况下我该怎么办?

我这样做是为了如果将来需要重命名类别名称。我可以重命名类别表中的那个。

那里有人告诉我使用数据模型。我想我应该尝试将从 callresponder 检索到的对象转换为我自定义的类对象,然后将此类设置为我的数据网格的数据提供者?这是应该做的吗

非常感谢示例代码。

【问题讨论】:

    标签: apache-flex datagrid


    【解决方案1】:

    您可以使用 DatagridColumn 的 labelFunction 属性,在该属性中分配一个函数来决定列中显示的内容:

    private function labelFunction(item:Object, column:DataGridColumn):String
    {
        //search for the categoryName
        for (var i:int = 0; i < categories.length; i++)
        {
            var category:Category = categories[i];
            if (category.cat_id == item.cat_id)
            {
                return category.categoryName;
            }
         }
         // in case it was not fault return a default value
         return "";
     }
    

    HTH 格斯

    【讨论】:

    • 应该这样做。非常感谢 Gus :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    • 2017-01-30
    相关资源
    最近更新 更多