2012-12-12 2 views
0

보내는 방법 모델의 배열을 백본에서 Post API 방법으로 보내시겠습니까?모델 콜렉션 backbone.js를 저장하는 데 최대 호출 스택 크기가 초과 되었습니까?

내 mvc 응용 프로그램에서 backbone.js를 사용하고 있으며 Rest API의 Post 메서드에 배열을 전달해야하는 시나리오가 있습니다. 배열 배열을 보내고 this.collection.create (model)를 호출하려고합니다. 나는

 var ModelArray = Backbone.Model.extend({ 
          urlRoot: av.api.patientInsuranceAddress, 
          toJSON: function() { 
           return this.collection.toJSON(); 
          } 
         }); 

         var modelCollection = new ModelArray(
          { 
           collection: this.collection.models 
          }); 

         modelCollection.save(); 

여기 e.models 내가 JSON과 Post 메소드를 호출로 변환 모델의 배열이 그대로 포스트 메소드를 호출하려고 거라고, 그리고 난이

같은 포스트 방법에 모델의 배열을받을하려면
public HttpResponseMessage Post(InsuranceAddressViewModel[] model) 
{ 
return null; 
} 

그러나 Post 메서드에서 null 배열이 나타납니다. json으로 모델의 배열을 변환하는 나의 방법은 괜찮습니까, 아니면 다른 것을해야 할 것입니다. 솔루션 몇 가지를 시도했지만 아이디어를 얻을 수 없었습니다. 컨트롤이 모델에서 toJSON에 올 때 나는이 solution

을 시도하고

안내하시기 바랍니다. Uncaught RangeError : 최대 호출 스택 크기를 초과했습니다. 기존 컬렉션에 모델을 추가하려고하거나 모델의 무리와 함께 컬렉션을 대체하기 위해 노력하고있다


I am posting my code here 

     var PayerAddress = Backbone.Model.extend({ 
     urlRoot: av.api.patientInsuranceAddress, 
     defaults: { 
     Address: '', 
     City: '', 
     State: '', 
     Zip: '' 
    }, 
     toJSON: function() { 
     return this.collection.toJSON(); 
     } 

        }); 

     var Payers = Backbone.Collection.extend({ 
     //url: av.api.patientInsuranceAddress, 
    model: PayerAddress, 

}); 

     "Done": { 
        class: 'btn', 
        text: "Done", 
        click: function() { 
         payerName = self.$el.find('#Payer').val(); 

         var ModelArray = Backbone.Model.extend({ 
          urlRoot: av.api.patientInsuranceAddress, 
          toJSON: function() { 
           return this.collection.toJSON(); 
          } 
         }); 

         var modelCollection = new ModelArray(
          { 
           collection: self.collection.models 
          }); 

         modelCollection.save(); 
         //self.closedialog(); 
         $(this).dialog("close"); 
        } 
       } 
+1

'myArrayofModels'는 배열이 아니며, 단일 문자열입니다. –

답변

0

안내하세요? 후자를 사용하는 경우 :

this.collection.reset(e.models); 

'. 모음에서 모델의 새로운 인스턴스를 만드는 데 사용되는'this.collection.create(myArrayofModels); 다음 위의 예에서는 문자열을 붙여 넣습니다. 그런 다음 백본은 그 문자열을 모델로 컬렉션에 추가하려고합니다.

+0

나는 내 질문과 내가 직면 한 문제를 편집했다. 나는 그것을 해결할 수 없다. plz guide someone – touseefkhan4pk

+0

어떻게 'modelCollection'을 채우고 있습니까? self.collection.models의 출처는 어디입니까? 크롬을 사용하고 있습니까? 그렇다면 dev 도구에서 네트워크로 이동 한 다음 게시물 호출을 클릭하고 헤더를 클릭하고 요청 페이로드를 복사하십시오. 여기에 붙여 넣어서 살펴볼 수 있습니다. – TYRONEMICHAEL

+0

내 모델에 내 컬렉션을 추가하겠습니다. 모델 인스턴스를 만들고 모델 컬렉션 (this.collection.models)을 사용하여 컬렉션 속성을 채우는 동안 모델 속성 컬렉션을 정의하고 있습니다. Actualy this.collection은 서버에 게시 할 모델 배열로 채워지는 내 컬렉션입니다. 가이드 요? – touseefkhan4pk

관련 문제