简体   繁体   English

EmberJS嵌套路由无法解决

[英]EmberJS nested route not getting resolved

I am trying to construct a simple address book app in EmberJS.RC.1 build as part of learning it. 我正在尝试在EmberJS.RC.1构建中构建一个简单的通讯录应用程序,作为学习它的一部分。 My routes are not getting through the initial checks. 我的路线没有通过初步检查。 What is the issue here? 这是什么问题? http://jsfiddle.net/Sz6fj/ http://jsfiddle.net/Sz6fj/

Error in console: 控制台错误:

Uncaught Error: assertion failed: Cannot call get with 'id' on an undefined object - ember-1.0.0-rc.1.js:52 未捕获的错误:断言失败:无法在未定义的对象上调用带有'id'的get -ember-1.0.0-rc.1.js:52

structure 结构体

contacts
contacts/new
contacts/<id>
contacts/<id>/edit

Code: 码:

App.Router.map(function(){
  this.resource('contacts', {path: '/'}, function(){
    this.route('new', {path: '/new'});
    this.resource('contact', {path: '/:contact_id'}, function(){
      this.route('edit', {path: '/edit'});
    });//contact
  });//contacts
});

It's because you don't have a contact_id on the model. 这是因为您在模型上没有contact_id If you change it to the primary key ( id ) then it will work just fine: http://jsfiddle.net/Sz6fj/1/ 如果将其更改为主键( id ),那么它将正常工作: http : //jsfiddle.net/Sz6fj/1/

contact_id does have a special usage on foreign keys. contact_id在外键上确实有特殊用法。

Try this: 尝试这个:

App.Router.map(function(){
  this.resource('contacts', {path: '/'}, function(){
    this.route('new');
    this.resource('contact', {path: '/contacts/:contact_id'}, function(){
      this.route('edit');
    });
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM