我有2条路线 - 会话和会话(因为我想在2个不同的页面中展示它们)
App.Router.map(function () {
this.route("sessions", { path: "/sessions" });
this.route("session", { path: "/sessions/:session_id" });
}
当我去:#/sessions
时 - 我得到一张漂亮的桌子,当我点击我制作的链接时
在车把视图中:
{{#each model}}
<tr>
<td>{{#link-to 'session' this}}{{this.id}}{{/link-to}}</td>
</tr>
它有效 - 会话的单独把手被绘制
当我直接转到#/sessions/4
时,我收到了错误消息:
Assertion Failed: You may not pass "undefined" as id to the store's find method
路线:
App.SessionsRoute = Ember.Route.extend({
model: function() {
return this.store.find('session');
}
});
App.SessionRoute = Ember.Route.extend({
model: function(params) {
return this.get('store').find('session', params.session_id);
}
});
答案 0 :(得分:0)
要使dynamic segments生效,您需要在声明路线时使用this.resource
:
App.Router.map(function () {
this.route("sessions", { path: "/sessions" });
this.resource("session", { path: "/sessions/:session_id" });
}