0

オブジェクト内で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() {

  }

}; 

これは、beforeSubmitが呼び出している場合に見られますがthis.submitRequest、その関数内では、myObjectのコンテキストを取得できません。コンテキストを渡す方法やmyObjectの他のプロパティにアクセスする方法はありますか?

ありがとうございました!

4

1 に答える 1

1

contextajaxのプロパティを使用します。

var options = {
    context: this
};
于 2013-03-21T21:27:31.503 に答える