I'm trying to build a view that is going to display multiple models and aggregated data.
After doing some reading in the docs, the {{render}}
helper is probably the right way to build a view like this. For setting the model normally I'd just set up a Route in which I pass the needed model data:
App.BuildingsRoute = Ember.Route.extend({
model: function() {
return this.store.find('buildings', '1');
}
});
But if I include a template via the {{render}}
helper, the route is not called. I'd like to know how I can pass the different models for each {{render}}
helper independently form each other, including first filtering the model?
The following may be relevant:
In your BuildingsRoute you can have all of the required logic to return all relevant models e.g.:
App.BuildingsRoute = Ember.Route.extend({
model: function() {
var self = this;
return new Em.RSVP.Promise(function (resolve, reject) {
new Em.RSVP.hash({
building: self.store.find('building', params.buildingId),
clients: self.store.find('client'),
products: self.store.find('product')
}).then(function (results) {
resolve({
building: results.building,
prods: results.broducts,
clients: results.clients,
foo: "bar"
});
});
}
});
See promises for more info on how to structure and chain these.
Then in your view you can access these models as follows:
{{render 'products' products}}
or
{{#each product in products}}
{{render 'product' product}}
{{/each}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With