0

I have a collection in Flex and I have sorted it by a date field, so the latest elements appear first in my view.

In order to do this I have applied a sort field like so:

var articleSort:Sort = new Sort();
articleSort.fields = [ new SortField('published', false, true), new SortField('id', true, true)];
articles.sort = articleSort;
articles.refresh();

Now I want to be able to use a cursor to findFirst() in that collection based on the id. However in order to do that I have to also pass through the published date in the findFirst() method. This is a real pain as I don't have the published date at that time, (or it's expensive to get).

articleCoursor.findFirst({ published: modelLocator.articles.getArticleById(event.newArticleId).published, id: event.newArticleId });

As you can see I am having to get it from the modelLocator in my application, and basically look up the item...

Ideally I would like to pass a wildcard though for the date in the FindFirst() function, as the id is the only thing I care about when searching. However it seems it Flex I can't do that.

The other option that occurred to me is to resort the collection before searching, but that would cause my view to re-render (as it's bound to the collection) on the collections refresh event. Plus it seems rather silly to have to resort in order to search.

Anyway, any advice on this would be great.

Thanks

Rob

1
  • There is some interesting stuff done by Tink here that may provide a solution to the problem, but it's not ideal: tink.ws/blog/collectionclone
    – robmcm
    Sep 11, 2009 at 9:31

1 Answer 1

0

you can resort your collection without refreshing the view if you call disableAutoUpdate() method on the collection, do your stuff, resort it back and then set it back with enableAutoUpdate(). Or you can not use the cursor and just do an array walk with for each and compare your id to find what you're looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.