Flex GroupingCollection:循环子级

发布于 2024-08-10 23:18:52 字数 178 浏览 5 评论 0原文

我正在使用 GroupingCollection 来绑定我的高级数据网格。我使用 groupingcollection 按日期对数据进行分组。

现在我需要通过代码选择数据网格中的数据。有谁知道如何做到这一点?我需要循环访问 adg 的数据提供程序并选择与选择标准相匹配的项目。

请指教

谢谢:)

I am using a GroupingCollection to bind my advanceddatagrid. I have used groupingcollection to group the data by date.

Now I need to select the data in the datagrid through the code. Does anyone have any idea as to how to do this? I need to loop through the adg's dataprovider and select the item that matches the criteria for the selection.

Please advise

Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

2024-08-17 23:18:52

好的,根据问题的解释方式,此代码将找到与所选分组年份匹配的项目。我向 mx:AdvancedDataGrid 添加了一个 click=findStuff(event),如下所示:

[Bindable]  
public var myData:ArrayCollection = new ArrayCollection([
    {name:'Denise', grad:'2000'},
    {name:'Steph', grad:'1990'},
    {name:'Jane', grad:'2000'},
    {name:'Nicole', grad:'2000'},
    {name:'Donna', grad:'1990'}]);

public function findStuff(e:Event):void {
    var groupColl:GroupingCollection = adGrid.dataProvider.source;
    var items:Object = groupColl.source;

    var ac:ArrayCollection = new ArrayCollection();
    for (var i:int=0; i<items.length; i++) {
        if (items[i].grad == e.target.text) {
            ac.addItem(items[i].name);
        }
    }
    Alert.show("selected items: " + ac.toArray());
}

<mx:GroupingCollection id="coll" source="{myData}">
    <mx:Grouping>
        <mx:GroupingField name="grad" />
    </mx:Grouping>
</mx:GroupingCollection>

<mx:AdvancedDataGrid id="adGrid" dataProvider="{coll}"
                         click="findStuff(event)"
                         initialize="coll.refresh()">
    <mx:columns>
        <mx:AdvancedDataGridColumn headerText="name" dataField="name"/>
    </mx:columns>
</mx:AdvancedDataGrid>

请注意,首先我从 AdvancedDataGrid dataProvider 获取 GroupingCollection,然后获取项目来自分组集合。这些可以合并为一个步骤,但这种方式对于示例来说更具可读性。由于不确切知道您要查找的数据,我只是从数据 item 中获取 name 字段,但您没有理由无法获取整个 item< /代码>。

希望这对您来说是朝着正确方向迈出的一步。

Okay, depending on how the question in interpreted, this code will find the items that match the grouping year that is selected. I added a click=findStuff(event) to the mx:AdvancedDataGrid, as shown here:

[Bindable]  
public var myData:ArrayCollection = new ArrayCollection([
    {name:'Denise', grad:'2000'},
    {name:'Steph', grad:'1990'},
    {name:'Jane', grad:'2000'},
    {name:'Nicole', grad:'2000'},
    {name:'Donna', grad:'1990'}]);

public function findStuff(e:Event):void {
    var groupColl:GroupingCollection = adGrid.dataProvider.source;
    var items:Object = groupColl.source;

    var ac:ArrayCollection = new ArrayCollection();
    for (var i:int=0; i<items.length; i++) {
        if (items[i].grad == e.target.text) {
            ac.addItem(items[i].name);
        }
    }
    Alert.show("selected items: " + ac.toArray());
}

<mx:GroupingCollection id="coll" source="{myData}">
    <mx:Grouping>
        <mx:GroupingField name="grad" />
    </mx:Grouping>
</mx:GroupingCollection>

<mx:AdvancedDataGrid id="adGrid" dataProvider="{coll}"
                         click="findStuff(event)"
                         initialize="coll.refresh()">
    <mx:columns>
        <mx:AdvancedDataGridColumn headerText="name" dataField="name"/>
    </mx:columns>
</mx:AdvancedDataGrid>

Note that first I get the GroupingCollection from the AdvancedDataGrid dataProvider, then I get the items from the GroupingCollection. These could be combined into one step, but this way is more readable for the example. Not knowing exactly what data you're looking for I just grab the name field from the data item but there's no reason you couldn't grab the whole item.

Hopefully this is a step in the right direction for you.

末骤雨初歇 2024-08-17 23:18:52

source 属性应包含数据的平面表示。

The source property should contain the flat representation of the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文