2013-04-26 190 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' 
相關問題