增加集合时分类收集和分类仍然存在? [英] Sort collection and sort remains in place when adding to collection?

查看:92
本文介绍了增加集合时分类收集和分类仍然存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我得到一个集合从服务层后面,我创建了一个ArrayCollection和应用排序。当我后来在一个项目添加到集合,排序还是很到位的?它似乎是这种情况。我以为我只是整理了一次,而不是施加那种会坚持???

下面是方法添加一个项目:

 私有函数onAddNewClick():无效
        {
            VAR fileTemplate:FileTemplateDetailDTO =新FileTemplateDetailDTO();
            fileTemplate.fileTemplateId = 0;
            fileTemplate.fileTmpltDtlId = 0;
            fileTemplate.createdBy = appModel.userName;

            newFieldsDp.addItem(fileTemplate);

            this.fieldsGridEmpty.rowCount = newFieldsDp.length + 1;
            totalCount = newFieldsDp.length;
            this.fieldsGridEmpty.scrollToIndex(totalCount);
        }
 

和这里是我现在正在尝试当数据回来的服务:

 每个(VAR DTO:FileTemplateCompositeDTO在科尔){
            dto.templateHistory = createHistoryColl(dto.details);
            VAR sortedArray:ArrayCollection的= sortDetails(dto.details);
            sortedArray.sort = NULL;
            VAR freshArray:阵列= sortedArray.toArray();
            dto.details.source = freshArray;
            model.fileTemplateComposites.addItem(FileTemplateCompositeDTO(DTO));
        }
 

解决方案

最简单的方式做了一次排序:

  VAR数组:数组= yourArrayCollection.toArray():
array.sortOn(SomePropertyAvailableInEachItem,Array.DESCENDING | Array.NUMERIC来);
yourArrayCollection.refresh();
 

既然你不排序的基础Array,而不是收藏。

When I get a collection back from the service tier, I create an ArrayCollection and apply a sort. When I add an item to the collection later on, the sort is still in place? It seems to be the case. I thought I was only sorting it once, not applying a sort that will stick???

Here is the method for adding an item:

private function onAddNewClick():void
        {
            var fileTemplate:FileTemplateDetailDTO = new FileTemplateDetailDTO();   
            fileTemplate.fileTemplateId = 0;
            fileTemplate.fileTmpltDtlId = 0;
            fileTemplate.createdBy = appModel.userName;

            newFieldsDp.addItem( fileTemplate );

            this.fieldsGridEmpty.rowCount = newFieldsDp.length + 1;
            totalCount = newFieldsDp.length;
            this.fieldsGridEmpty.scrollToIndex( totalCount );
        }

And here is what I'm trying now for when the data comes back from the service:

for each( var dto:FileTemplateCompositeDTO in coll ){
            dto.templateHistory = createHistoryColl( dto.details );
            var sortedArray:ArrayCollection = sortDetails( dto.details );
            sortedArray.sort = null;
            var freshArray:Array = sortedArray.toArray();
            dto.details.source = freshArray;
            model.fileTemplateComposites.addItem( FileTemplateCompositeDTO( dto ) );
        }

解决方案

Easiest way to do a one time sort:

var array:Array = yourArrayCollection.toArray():
array.sortOn("SomePropertyAvailableInEachItem", Array.DESCENDING | Array.NUMERIC);
yourArrayCollection.refresh();

Since you're not sorting the underlying Array, and not the collection.

这篇关于增加集合时分类收集和分类仍然存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆