我正在尝试编写电子商务风格的Ember App。我正在对它进行建模(这是一项任务,我认为这将是学习Ember的一个很好的借口。)https://www.humblebundle.com/store是我正在追求的模型。
我想在索引路线上显示两种类型的内容 - Promos和Games,因为它们的显示方式不同。
Store.Router.map(function() {
this.resource('promos', function(){
});
this.resource('games', function(){
});
});
我目前将索引重定向到促销 - 但实际上,我希望将促销和游戏渲染到他们自己的命名网点。有没有这方面的指南?到目前为止,似乎所有内容都涉及制作一次只关注一个问题的应用程序。
答案 0 :(得分:2)
您应该在路线上使用renderTemplate()
,如下所示:
Store.IndexRoute = Em.Route.extend({
model: function(){
return {
games: ['checkmates', 'magic the gathering', 'flappy bird'],
promos: ['1','42']
};
},
renderTemplate:function(){
this.render('games', { outlet: 'games' });
this.render('promos', { outlet: 'promos' });
}
});
JSBin在这里 - http://jsbin.com/jupet/2/edit
答案 1 :(得分:0)
这就是我目前正在做的事情。代码有效,但我不确定它是否是“正确的方式”。
Store.IndexRoute = Em.Route.extend({
// Hook that runs when the controllers are being set up.
setupController: function(controller, model) {
this.controllerFor('promos').set('model', this.store.find('promo'));
this.controllerFor('games').set('model', this.store.find('game'));
controller.set('content', model);
}
然后,在索引模板中:
{{render "promos"}}
{{render "games"}}
事情正在发挥作用,GamesController和PromosController正在连接到正确的模型。