2012-11-19 4 views
0

마지막으로 포기했습니다. 나는 이걸 작동 시키려고 노력하지만 운이 없다.백본 컬렉션. 모델을 로컬로 생성하지 않습니다.

    var createData = { 
         full_name : full_name, 
         email : email, 
         role_id : role_id 
        }; 

        var that = this; 
        app.collections.teamMembers.create(createData,{ 
         wait: true, 
         success : function(){ 
          log("in success") 
         }, 
         error : function(a,b,c){ 
          log("in error") 
         } 
        }) 

서버가 PHP이며이 같은 결과 반환 : 나는 단순히 이런 collection.create 호출이 위에서

header('Content-type: application/json'); 
    echo json_encode(array(
     "data" => $data, 
     "meta" => $meta 
    )); 

을하는 $ 데이터 배열 ("실제로 attr "=>"val ", ...)이 컬렉션의 모델이 정의 된 방식과 정확히 일치합니다.

parse : function(response){ 
     log(response, "inside model parse, this is the response from server") 
     return response.data; 
    }, 

:

문제는이 같은 모델에 model.parse을 사용하여 내가 직접 JSON을 반환하지하고 있기 때문에 원래의 모델과 유사한 개체를하지만, 네임 스페이스 지정 (데이터/메타)를 사용한다는 것입니다 문제 : 모델이 클라이언트 측에서 생성되지 않습니다. '추가'이벤트가 발생하지 않습니다. 나는 또한 wait : true 옵션을 사용하고있다. - wait를 사용하지 않습니다. true - wait true를 사용하지만 이름 공간이없는 정확한 JSON 모델을 서버에서 반환합니다.

나는 네임 스페이스뿐만 아니라 wait : true를 사용하고 싶다. 제발 도와주세요 : (

+0

, 그것은 성공 콜백에 들어가 않습니다 –

+0

내가 모델에 기본 해시가없는, 즉이 필요하다? –

+0

업데이트 : 내가 지적한 또 다른 점은 .create 메서드가 유효한 모델을 반환한다는 것입니다 (창에 저장 한 다음 콘솔을 사용하여 값을 읽음). 그러나 새 모델은 아직 삽입되지 않았습니다. 이상한! –

답변

0

마지막으로 나는 그것을 고칠 수 있었다. 나는 백본 컬렉션과 모델을 내 부트 스트랩에 오버라이드하여 어쨌든 사용하지 않을 로딩 상태를 갖게되었다. 그래서 나는 전체 코드를 주석 처리했다. .! 이것이 내가 주석 내 부트 스트랩의 코드이었다 : 서버가 응답 후

또한
// OVERRIDINGS AND SETTINGS 
    //---------------------- 

    // Adding close method to all views 
    Backbone.View.prototype.close = function() { 
     if (this.onClose) { 
      this.onClose(); 
     } 
     _.each(this.childViews, function(childView){ 
      childView.close(); 
      delete childView; 
     }) 
     this.remove(); 
     this.unbind(); 
    }; 

    // Adding loading state to every model and collection 
    Backbone.Collection.prototype.loading = false; 
    Backbone.Model.prototype.isLoading = false; 

    // Set isLoading to true when fetch starts 
    var oldFetch = Backbone.Collection.prototype.fetch; 
    Backbone.Collection.prototype.fetch = function(options) { 
     this.isLoading = true; 
     oldFetch.call(this, options); 
    } 
    Backbone.Model.prototype.fetch = function(options) { 
     this.isLoading = true; 
     oldFetch.call(this, options); 
    } 

    // Turn off isLoading when reset 
    Backbone.Collection.prototype.on('reset', function(){ 
     this.isLoading = false; 
    }) 
    Backbone.Model.prototype.on('reset', function(){ 
     this.isLoading = false; 
    }) 
관련 문제