L0ck3
asked on
Flex nested ArrayCollections sorting
Hi experts,
I have an ArrayCollection nested in another one. I need to sort the child collection by a field.
I tried the following code. It works fine for the parent collection, but does nothing for the child one.
L0ck3
I can't figure out what I'm doing wrong, so some help would be appreciated.
Thanks in advance,
I have an ArrayCollection nested in another one. I need to sort the child collection by a field.
I tried the following code. It works fine for the parent collection, but does nothing for the child one.
L0ck3
// The Data
public class Data
{
public var value:String;
public var otherValue:String;
public var childrenData:ArrayCollection; // An array collection containing Data objects.
}
// The sorting function
private function sortData():void
{
var records:ArrayCollection() = bla bla (init the collection with some Data objects).
records.sort = new Sort();
records.sort.fields = [
new SortField('value', true, false)
];
for each (var data:Data in records){
sortChildren(data);
}
records.refresh();
}
private function sortChildren(data:Data):void
{
if (data.childrenData != null) {
var srt:Sort = new Sort();
srt.fields = [
new SortField('otherValue', true, false)
];
data.childrenData.sort = srt;
data.childrenData.refresh();
}
}
I can't figure out what I'm doing wrong, so some help would be appreciated.
Thanks in advance,
ASKER
In my "real world application", this data comes from a java server via BlazeDS.
The only code for initialization of the collection on Flex side, is the following :
The class I named "Data" is also a more complex one, but it is not supposed to deal with the problem.
The only code for initialization of the collection on Flex side, is the following :
records = rpcEvent.result as ArrayCollection;
The class I named "Data" is also a more complex one, but it is not supposed to deal with the problem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for answering.
The collection contains other objects of type Data. I want the parent records to be sorted by the "value" fields and the children of each record to be sorted by the "otherValue" field.
The collection contains other objects of type Data. I want the parent records to be sorted by the "value" fields and the children of each record to be sorted by the "otherValue" field.
I see.
Shouldn't the field be specified by a string between double quotes?
new SortField("otherValue", true, false)
instead of
new SortField('otherValue', true, false)
Shouldn't the field be specified by a string between double quotes?
new SortField("otherValue", true, false)
instead of
new SortField('otherValue', true, false)
ASKER
I tried, but ir didn't change anything. In AS3 strings can be defined by single or double quotes.
>> It works fine for the parent collection, but does nothing for the child one.
How do you check that?
By printing them out? Or by inspecting them in your IDE?
In sortchildren() try printing out
data.childrenData
to check it contains what you expect (Data objects having the "otherValue" property)
How do you check that?
By printing them out? Or by inspecting them in your IDE?
In sortchildren() try printing out
data.childrenData
to check it contains what you expect (Data objects having the "otherValue" property)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
>> var records:ArrayCollection() = bla bla (init the collection with some Data objects).