2013-02-10 2 views
1

나는 Band 엔터티로 작업하는 간단한 앱을 가지고있다. 사용자가 기존 레코드를 업데이트 할 수있는 양식을 만들었습니다. 이 컨트롤러에 의해 처리 것 :Ember Data 객체를 여러 번 업데이트하는 방법은 무엇입니까?

App.BandEditController = Ember.Controller.extend({ 

    startEditing: function() { 
     var band = this.get('model'); 
     var transaction = band.get('store').transaction(); 
     transaction.add(band); <-- THIS IS THE PROBLEM (IN 2ND RUN) 
     this.transaction = transaction; 
    }, 

    stopEditing: function() { 
     // rollback the local transaction if it hasn't already been cleared 
     var transaction = this.transaction; 
     if (transaction) { 
      transaction.rollback(); 
      this.transaction = undefined; 
     } 
     this.startEditing(); 
    }, 

    save: function() { 
     this.transaction.commit(); 
     this.transaction = undefined; 
     this.stopEditing(); 
    }, 

    cancel: function() { 
     this.stopEditing(); 
    } 
}); 

는 그것은 상당히 이것에 의해 영감을 :

내가 양식을 표시하고, 한 번에 모든 게 OK를 편집을 수행 https://github.com/dgeb/ember_data_example/blob/master/app/assets/javascripts/controllers/contact_edit_controller.js. 그러나 양식을 표시된 상태로 유지하고 사용자가 다시 편집 할 수있게하고 싶습니다. 나는 같은과 다른 거래를 만들 수 없습니다 이해

Uncaught Error: assertion failed: Once a record has changed, you cannot move it into a different transaction 

: 내 접근 방식을 통해 즉시 startEditing 방법은 다시 거래 밴드를 추가하려고 서버에 업데이트 된 기록을 전송 한 후,이 오류가 발생합니다 목적. 하지만 왜? 어떻게 해결할 수 있습니까?

(Btw는 그 거래, startEditing과로 stopEditing 방법보다 기록을 갱신하기위한 어떤 더 간단 방법이 있습니다 그것은 나에게 조금 잔인한 것 같다?.) 당신은 stopEditing에서 this.startEditing(); 호출

답변

0

-이 이상한 것 같다. 원래 코드에는 그런 행이 없습니다. 다시 모델을 변경하기 전에 당신이 다른 곳에서 startEditing을 요구하는 경우,이 ..이 두 번 호출 할 또한

의 원인이됩니다, AFAIK, 당신은

.. 서버 응답을 기다릴 필요
관련 문제