I have the following RSVP hash in my IndexRoute which finds all slider records ( I need to use a hash because I need to load 2 models on this page). I can call sliders or this.sliders in the index template to successfully pass all the slider objects to a view component.
However, I need to filter these records by the page attribute "index". When I add filterBy to the IndexRoute, no records are returned.
How can I filter these records and use the resulting array in the template?
IndexRoute
App.IndexRoute = Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({
sliders: this.store.findAll("slider"), # Adding .filterBy("page", "index") fails to load anything
products: this.store.findAll("products")
});
}
});
index.html
<script type="text/x-handlebars" data-template-name="index">
{{mainpage-slider sliders=sliders}}
</script>
add the filter to the controller
App.IndexRoute = Ember.Route.extend({
model: function() {
return Ember.RSVP.hash({
sliders: this.store.find("slider"), # Adding .filterBy("page", "index") fails to load anything
products: this.store.find("products")
});
}
});
App.IndexController = Em.ObjectController.extend({
filteredSlider: function(){
return this.get('sliders').filterBy('page', 'index');
}.property('sliders.@each.page')
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.