That is part of the challenge. I need to query the server, which I understand how to do. But the design requirement is to display the search selector ui and the search results table ui on the same page. This is where ember really confuses me.
Also, I imagine something can be done with query params. But managing view hierarchy and talking to multiple models/controllers at the same time is the hard part for me.
Thinking about this a little more I suppose I could use the active hook in one route or controller to load up the the data from another route/controller.
The issue is that I need to get data from a route/controller that will never be directly navigated to.
I just canât quite figure out the syntax to do this. Basically reach over to the another route/controller and say âhey fetch your data, I need it nowâ.
This is a very specific case because of the way the models are defined in my domain.
I think youâre clinging to concepts from older routing code that donât really apply here. I definitely wouldnât have a search conditions route.
Hereâs a potential solution:
In the beforeModel hook of the search route, I would load the search conditions using a promise with a .then() that sets a searchConditions property on the search controller on a successful load.
I would not define a model hook on the search route.
Next, Iâd define a search action on the search route that parses the search conditions/terms, performs the ajax call that does the search, and sets the content (and/or multiple other attributes) of the search controller when the ajax call returns.
Then, I would assign the search action to the form on the search template â i.e. <form {{action "search" on="submit"}}>.
Then, Iâd render the results of the search action somewhere within the search template.
Yeah, I think that makes sense overall. I can be really stubborn in my coding patterns. Thanks for the feedback.
I just need to get more sophisticated with my use of promises.
I am still wondering about the case of trying to load two disparate models at the same time. Wonder if it ever makes sense to do something like this:
beforeModel: function() {
RSVP.Promise.all([
this.store.find('foo'),
this.store.find('bar'),
]).then(function(values){
values[0]; // => foos
values[1]; // => bars
// do some work to set the controller here
// ...
return values;
});
}
@eccegordo, are you using ember-data? Itâs totally ok to push data into your store if you need it, even if you havenât visited the route. There is no 1:1 mapping between a routeâs model and the records you have in the cache, in fact, model used to be named something else, but I canât remember what.
http://emberjs.com/api/classes/Ember.Route.html#method_controllerFor
Returns the controller for a particular route or name.
The controller instance must already have been created, either through entering the associated route or using generateController.
The concept is the same. If you havenât visited a route yet, then the model hook wonât be called, and that means the data will come out undefined. In case you are writing a route that needs multiple models, but havenât transitioned into their corresponding routes yet, then you can push their data into the store when you need it. This probably means that you have a complex route that happens to come in early in your app.
For the most part, you can just call the store and set it to whatever property in your controller that you want. If you want to boost performance, you can generate the supporting controllers beforehand, and seed them. When you actually visit the supporting routes, and youâre using Ember Data you wonât need fetch data. If you are using your own youâll have to implement some form of caching.
This is usually what I do, although I use Ember.RSVP.hash, and then use controllerFor in setupController if I need to. But you can merge the two arrays and just pass them into your controller. Thatâs probably the clearest way to accomplish this.