2013-08-27 26 views
1

我正在用用戶註冊構建一個ember.js web應用程序。如果註冊失敗(例如無效的電子郵件),則API返回錯誤。問題是這會使模型進入錯誤狀態,如果用戶試圖再次嘗試註冊,Ember.js會提出錯誤Uncaught Error: Attempted to handle event 'willSetProperty' on <App.User:ember451:null> while in state rootState.error.,然後似乎變得沒有響應。在Ember.js中,模型如何從請求錯誤中恢復?

是否必須手動重置錯誤後的狀態?

becameInvalid: function() { 
    // reset the state after an error 
    var parentState = this.get('stateManager').get('currentState').parentState.dirtyType; 
    if (parentState === "updated") { 
     this.get('stateManager').transitionTo('loaded.updated'); 
    } else { 
     this.get('stateManager').transitionTo('loaded.created.uncommitted'); 
    } 

    } 

這似乎有點奇怪。我是否設置錯誤?有沒有其他方法,或者我應該在錯誤後重置?

回答

1

是否必須手動重置錯誤後的狀態?

是的。

這似乎有點奇怪。

同意。當然,它將在未來版本的ember-data中得到改進。

我是否設置錯誤?

不,你這樣做是正確的

有另一種方式,或者我應該錯誤後復位?

沒有其他辦法AFAIK。

看到這篇文章:Ember: transaction.commit does not fire after becameInvalid event

0

您必須手動重置狀態。 Ember本身不涉及模型管理。 Ember-Data和Ember-Model(與Ember分開)有能力回滾/恢復「髒」模型。