【问题标题】:EmberJS nested route not getting resolvedEmberJS 嵌套路由没有得到解决
【发布时间】:2013-02-18 19:52:09
【问题描述】:

我正在尝试在 EmberJS.RC.1 中构建一个简单的地址簿应用程序,作为学习它的一部分。我的路线没有通过初始检查。这里有什么问题? http://jsfiddle.net/Sz6fj/

控制台错误:

未捕获的错误:断言失败:无法在未定义的对象上使用 'id' 调用 get - ember-1.0.0-rc.1.js:52

结构

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

代码:

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

【问题讨论】:

    标签: javascript ember.js ember-data


    【解决方案1】:

    这是因为模型上没有contact_id。如果你把它改成主键(id)那么它就可以正常工作:http://jsfiddle.net/Sz6fj/1/

    contact_id 确实对外键有特殊用途。

    【讨论】:

      【解决方案2】:

      试试这个:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-04-27
        • 2011-01-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多