2013-03-21 2 views
0

내가 개체 내에서 jQuery forms plugin을 사용하고 있습니다에 컨텍스트를 전달하는 플러그인이 :jQuery를 양식은 예를 들어, 요청 및 응답

var myObject = { 

    el : $('#form'), 

    init : function() { 

    var options = { 
     beforeSubmit: this.submitRequest, 
     success: this.submitResponse, 
     error: function(xhr, reply, error) { 

     } 
    }; 

    this.el.ajaxForm(options); 

    }, 
    submitRequest : function(formData, jqForm, options) { 

    //this no longer contains the el attribute or access to any other myObject properties  
    console.log(this); 

    }, 
    submitResponse : function() { 

    } 

}; 

당신은 그게 this.submitRequest를 부르고 beforeSubmit, 경우에서 볼 수 있지만, 그 함수 내에서, myObject의 컨텍스트를 가져올 수 없습니다. 컨텍스트를 전달하거나 myObject의 다른 속성에 액세스하는 방법에 대한 아이디어가 있습니까?

감사합니다.

답변

1

아약스의 context 속성을 사용하십시오.

var options = { 
    context: this 
}; 
+0

완벽! 고맙습니다 :) – dzm