【发布时间】:2016-05-03 17:24:18
【问题描述】:
我遇到了与here 所述相同的问题,但不明白它如何适用于我的情况,因为我没有“显示”路线。
我继承了这个app,router.js长这样:
App.Router.map(function() {
this.route('index', {
path: '/'
});
return this.resource('parent', {
path: '/:parent_id'
}, function() {
this.resource('games', {
path: '/games'
});
return this.resource('game', {
path: '/game/:game_id'
});
});
});
后端是 Rails,当在 Ember 中点击 /games url 时,它会按预期调用 Rails GamesController 中的 games Index 操作。
游戏模板渲染每个游戏:
<ul class="gamesList">
{{#each game in sortedGames}}
{{#link-to 'game' game class='gameItem u-cf' tagName='li'}}
<div class="gameItem-name u-before6of12 u-after1of12">{{game.name}}</div>
<div class="gameItem-description u-before6of12 u-after1of12">{{game.description}}</div>
{{/link-to}}
{{/each}}
但是当点击游戏链接时,它会从 Ember 商店加载游戏,并且不会向 API 发出请求。
我需要它来向 API 发出请求,因为: 1. 游戏列表只包含名称和描述,因为列表可以包含很多游戏,所以我们只想为每个游戏加载数据的一个子集。 2. 由 Rails Show 动作加载的单个游戏应该使用不同的序列化程序来加载单个游戏的所有附加内容(包括嵌入的子对象)。
这是游戏路线:
App.GamesRoute = Ember.Route.extend(Easypeasy.ResetScroll, {
model: ->
return this.store.find('game', {
parent: @modelFor('parent').get('slug')
})
})
这是游戏路线:
App.GameRoute = Ember.Route.extend(App.ResetScroll)
如何触发 Ember 加载用户点击的单个游戏?
【问题讨论】:
标签: javascript ruby-on-rails ember.js ember-data