PDA

View Full Version : How catch "this" ?



j4meson
30 Jul 2012, 10:54 AM
Hi all,

I can't catch the good 'this', under my talk you can see a sample from my code in sencha mvc controller,
the function ' this.getExpression' catch the good 'this' corresponding the controller it's good so i can use the functions declared in it.
but 'this.emailRequest' catch 'form' for 'this'
Thanks a lot for your help =)


'#sendEmail': {
click: function (button) {
var contact = Ext.ComponentQuery.query('contact')[0];
var form = button.up('window').down('form').getForm();
var mask = new Ext.LoadMask(button.up('window'), { msg: this.getExpression('Sending the email...') });

mask.show();

form.submit({
success: function (form, action) {
this.emailRequest(mask, contact, 'Information', action.result.message);
},
failure: function (form, action) {
this.emailRequest(mask, contact, 'Information', action.result.message);
}
});

}
}

Tim Toady
30 Jul 2012, 1:58 PM
You can either put "this" in a variable prior to the submit and reference that in your success and failure function or you can specify "scope: this" in your form.submit config.

sword-it
30 Jul 2012, 11:09 PM
try this:-




'#sendEmail': {
click: function (button) {
var contact = Ext.ComponentQuery.query('contact')[0]
, form = button.up('window').down('form').getForm()
, mask = new Ext.LoadMask(button.up('window'), { msg: this.getExpression('Sending the email...') })
, me=this;

mask.show();
form.submit({
success: function (form, action) {
me.emailRequest(mask, contact, 'Information', action.result.message);
},
failure: function (form, action) {
me.emailRequest(mask, contact, 'Information', action.result.message);
}
});
}
}

j4meson
30 Jul 2012, 11:54 PM
thanks both of all, it works like a charm ;-)