emberjs直接访问资源不工作

时间:2014-10-27 09:18:21

标签: ember.js routes

我有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);
    }
});

1 个答案:

答案 0 :(得分:0)

要使dynamic segments生效,您需要在声明路线时使用this.resource

App.Router.map(function () {
    this.route("sessions", { path: "/sessions" });
    this.resource("session", { path: "/sessions/:session_id" });
}