I have flat data in my app which I will need to group, summarize, and count as I normally wo开发者_如何转开发uld with a sql query. For this project though, it must be done in the flex app. I need to figure out how to group my data by day or month using a datatime field in my Arraycollection, then appropriately count or summarize data in other fields. I've used Groupingcollections before, but only when binding to hierarchical controls (like AdvancedDataGrid and Tree), but I need a resulting ArrayCollection with the grouped and summarized data.
Basically, I'm trying to access my AC like a sql table (GROUP BY MONTH(datetime), COUNT, COUNT(DISTINCT(), etc.) and I'm unsure how to do it. Does anyone have experience doing this?
You can give ActionLinq (https://bitbucket.org/briangenisio/actionlinq/wiki/Home) a try. I've not used it myself, but I've been itching to give it a try :)
It's an implementation of Linq (from C#) in actionscript. This gives you a functional way of dealing with collections of data in a very SQL-like manner (select, group, filter, etc.).
I would characterise it like the filter
method on steroids.
Here is an example from the website - it shows some of the SQL-like names and how the chaining works:
var transformed:Array =
[-4, -3, -2, -1, 0, 1, 2, 3, 4]
.where(isEven)
.select(square)
.distinct()
.reverse()
.toArray();
assertThat(transformed, array(0, 4, 16));
More information and examples here: http://riarockstars.com/2011/02/07/processing-data-on-the-clientactionlinq/
You may find that this example points you in the right direction http://flexdiary.blogspot.com/2008/09/groupingcollection-example-featuring.html
精彩评论