Login Register

I'm looking for suggestions on a better way to iterate through my dojo.data store to decrease # of iterations

Sorry that's a pretty vague subject. What I have is a store of items like this:

items: 
[
  { name: "button", category: "core", imageSrc: "image.png", label: "Button", description: "It's a button!" }, 
  and repeat...
]

Let's say I have a hundred items. I need to know first how many different categories I have to populate (I won't know this before hand) in an AccordionContainer with AccordionPanes, one pane to one category, and each pane needs to be populated with the category items widget that uses the image, description etc attributes. I wanted to create the container and then populate it immediately and then move onto the next container category.

What I have so far, but it has a iteration flaw, that I'll mention later is:
I do a fetch on the store by category. onItem I take the category string value and push it onto an array and then do an inner fetch in the onItem handler that just looks for items with that category using a query and creates them in the current category AccordionPane. Each time the first fetch enters the onItem handler I check to see if I already have this category in my list, if I do all the items have already been made and I return, else I push the category value onto the array and again fetch all relative items from the store with that category.

The flaw: This means that I search the whole store top to bottom for the categories once and I also search the whole store each time a new category is found and pushed onto the array. This seems like a lot of iterations through the store. Is there a better way to do this? I don't really want to use two stores... one for category and one for items. Maybe there's a better way to set up my store...

Would having your server

Would having your server provide the data sorted by category (and maybe by sub category) let you do one pass?