2013-01-21 42 views
2

在這種jsfiddle編輯記錄,我有EmBlog.PostsNewRouteEmBlog.PostsEditRoute。路線包含'保存,取消和銷燬'事件。emberjs新路由器-V3 /控制器無法創建或使用燼數據

當我創建一個新的記錄,它只是在內存中創建它,不會調用store.commit(),並在控制檯,它拋出的錯誤:

遺漏的類型錯誤:無法調用「提交」未定義

當我嘗試編輯時,它會拋出同樣的錯誤,但編輯仍然只發生在內存中。

銷燬行爲也失敗。

當我打電話取消,我得到:

無法讀取的不確定

大部分的代碼是財產 'defaultTransaction' 在jsfiddle。保存並取消事件跟隨描述的圖案由Yehuda here

App.NewUserRoute = Ember.Route.extend({ 
     model: function() { 
     return App.User.createRecord(); 
     }, 

    events: { 
     save: function(user) { 
      this.get('store').commit(); 
     } 
    } 
    }); 

感謝

回答

5

更新fiddle!它現在正在創建,編輯和銷燬用例。詳情參見下面的什麼,我改變......

When I create a new record, it only creates it in memory and never calls the store.commit() and in the console, it throws the error: Uncaught TypeError: Cannot call method 'commit' of undefined

PostNewRoute失敗,因爲this.store是不確定的。 this.content也是未定義的。

save: function(post) { 
    this.store.commit(); 
    this.content.addObserver('id', this, 'afterSave'); 
}, 

更新後的版本調用了對帖子交易的提交。在創建記錄後也使用post.one回調進行轉換。

save: function(post) { 
    post.one('didCreate', this, function(){ 
    this.transitionTo('posts.show', post); 
    }); 
    post.get('transaction').commit(); 
}, 

將與其他更新的詳細信息後更新...

When I try to edit, it throws thesame error but then the edit still happens only in memory.

The destroy action also fails.

When I call cancel, I get: Cannot read property 'defaultTransaction' of undefined

+0

固定這個@Micheal非常感謝。祝您愉快。 – brg