[英]Multiple models in Application route, how to setup the controller Ember.JS
[英]Filter multiple models by attribute in ember.js Route
我的IndexRoute中有以下RSVP哈希,可以找到所有滑塊記錄(我需要使用哈希,因為我需要在此頁面上加載2個模型)。 我可以在索引模板中調用滑塊或this.sliders來成功將所有滑塊對象傳遞給視圖組件。
但是,我需要通過頁面屬性“索引”過濾這些記錄。 當我將filterBy添加到IndexRoute時,沒有記錄返回。
如何過濾這些記錄並在模板中使用結果數組?
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>
將過濾器添加到控制器
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')
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.