PDA

View Full Version : Access to instances from callback



stoertebeker
16 Apr 2012, 12:34 PM
Hi,
I have the following situation within a controller:


//user is an instance of UserLogin (model)
var user = Ext.create(model, this.getLoginform().getValues());


user.save({
success: function(record) {
console.log('Login success');
console.log(record.get('lastname'));
var mvp = Ext.getCmp('myviewport');
console.log(mvp);
},...

What I actually want, is to access an attribute that is part of the view MyViewport. I have also defined a reference to MyViewport (-> myviewport). What i get back from Ext.getCmp() is a pointer to the DOM object and not to the instance of MyViewport.
Outside of the callback I can access the sttribute via this.getMyviewport().attribute.
Maybe i have a fundamental misunderstanding or there is any other mistake.

Any comment or hint is welcome.

dedoz
16 Apr 2012, 12:51 PM
you can set the callback scope "where to execute your callback function"

if your user.save is inside a controller method then just pass "this" as scope



user.save({
success: function(record) {
console.log('Login success');
console.log(record.get('lastname'));
var mvp = Ext.getCmp('myviewport'); console.log(mvp);
},...
scope : this
});

now inside the callback function "this" will point to the controller