Passing a list of values or objects to another route/controller


#1

I have one route that is displaying a list of objects and the user is able to check the objects/rows that are displayed. Next they click a button that goes to another route that needs the user to enter in information about the things that were selected.

Now here’s where my confusion comes in. How do I pass the list of objects or a list of the ids for the objects to the other route? The other route is using an ArrayController already for a list of options on that route (might be the incorrect way to do that)

I tried using transitionToRoute in the first list’s controller and passed in a list of the selected objects but it gives me

More context objects were passed than there are dynamic segments for the route

I figure I’m not using the nested routes correctly and that maybe I need a resource and then put each route under the resource, and the common parent resource manages the selected items?

What does everyone else normally do? What is the nested route structure supposed to look like in this scenario? I tried the needs option but I think I may have done it incorrectly

If this is confusing or you need more info let me know and maybe I can draw a representation of what I am doing


#2

I made a JSBin that shows how you can pass a list of objects to a route.

You have 2 options, via actions or via link-to. Both options require that your receiving route accepts a parameter.


#3

Hi, an issue I have here is that (from what I read) it’s generally not good to use more than 2k characters in the URL. I don’t expect that there will be that many characters being serialized but someone is bound to select so many options and cause this issue and complain

Is there a way to pass models without serializing to the URL?

Or does this sound like it should be all done in one “page” and the second template loaded over the first one?

Should there be a parent and a sub route with the list, and then a sub route that uses the selection from the list, and then the parent contains the selection so that the second sub route has access to the list through “needs”?


#4

@Arch I think query-params is what you need.
Refer this guide, and check if it’s useful for you.


#5

The JSBin really helped me a lot. Thanks :slight_smile: