2013-04-26 108 views
0

我正在尝试构建一个简单的CRUD,就像在单个模型上工作的EmberJS应用程序。Ember未捕获RangeError:超过最大调用堆栈大小

我的路线是这样的现在:

Blog.ApplicationRoute = Ember.Route.extend() 

Blog.Router.map -> 
    @route 'about' 
    @resource 'posts', -> 
    @route 'new' 
    @resource 'post', { path: '/:post_id' }, -> 
     @route 'edit' 

Blog.PostsRoute = Ember.Route.extend 
    model: -> Blog.Post.find() 

Blog.PostsNewRoute = Ember.Route.extend 
    model: -> Blog.Post.createRecord() 
    events: 
    save: -> 
     console.log @ 
     @.get('currentModel').get('store').commit() 
     @.transitionTo('posts') 


Blog.PostEditRoute = Ember.Route.extend 
    model: -> @modelFor('post') 
    events: 
    update: -> 
     @.get('currentModel').get('store').commit() 
     @.transitionTo('posts') 

我的HTML视图中包含一些简单的车把模板:

%script#about{type: "text/x-handlebars"} 
    %h2 About... 

%script#posts{type: "text/x-handlebars"} 
    .row-fluid 
    .span4 
     %h4 Posts 
     %ul 
     = hb 'each model' do 
     %li 
      = hb 'linkTo "post" this' do 
      = hb 'title' 

     = hb 'linkTo "posts.new"' do 
     New Post 
    .span8 
     = hb 'outlet' 

%script#post{type: "text/x-handlebars"} 
    %h2= hb 'title' 
    = hb 'body' 
    %p 
    = hb 'linkTo "post.edit" this' do 
     Edit 
    = hb 'outlet' 

%script{id: 'posts/new', type: "text/x-handlebars"} 
    %h2 New Post 
    %p 
    = hb 'view Ember.TextField', valueBinding: 'title' 
    %p 
    = hb 'view Ember.TextArea', valueBinding: 'body' 
    %p 
    %button{hb: 'action "save"'}Save 


%script{id: 'post/edit', type: "text/x-handlebars"} 
    %h2 Edit Post 
    %p 
    = hb 'view Ember.TextField', valueBinding: 'title' 
    %p 
    = hb 'view Ember.TextArea', valueBinding: 'body' 
    %p 
    %button{hb: 'action "update"'}Save 

该指数上市,预期新的形式和节目模板的工作。当我点击“编辑”按钮,我得到以下错误在JavaScript控制台:

Uncaught RangeError: Maximum call stack size exceeded 

我可以通过我的浏览器地址栏中直接访问编辑路线,没有任何问题:

/#/posts/1/edit 

当前的布局结构会在show模板下面呈现编辑模板,对应于我正在使用的嵌套路线。

堆栈跟踪看起来像这样:

contentPropertyDidChange 
sendEvent 
Ember.notifyObservers 
propertyDidChange 
ChainNodePrototype.chainDidChange 
ChainNodePrototype.chainDidChange 
ChainNodePrototype.didChange 
chainsDidChange 
propertyDidChange 
contentPropertyDidChange 
sendEvent 

我很无能,为什么contentPropertyDidChange事件,但只是点击编辑按钮触发。

回答

1

我找到了答案在ember.js: stack overflow with a route

关键是要建立与model代替this编辑路线:

%script#post{type: "text/x-handlebars"} 
    %h2= hb 'title' 
    = hb 'body' 
    %p 
    = hb 'linkTo "post.edit" model' do 
     Edit 
    = hb 'outlet' 
相关问题