Hi, this is very simpy question :">
Example = new Ext.app.App({
permissions: 15, // FIRST
init : function(){
Ext.QuickTips.init();
Ext.Ajax.request({
url : 'index.php?permissions=check',
success: function ( resp, opt ) {
this.permissions = 5; // SECOND
}
});
}
});
Example.MainMenu = Ext.extend(Ext.app.Module, {
init : function(){
alert(Example.permissions);// I'm see 15, but want to see 5. HowI can make this var public?
}
});
Thanks.
If you're instantiating Ext.app.App class you cannot have private variables w/o changing the class you instantiate. The code in this case would be:
Example = new Ext.app.App({
permissions: 15, // FIRST
init : function(){
Ext.QuickTips.init();
Ext.Ajax.request({
url : 'index.php?permissions=check',
scope : this,
success: function ( resp, opt ) {
this.permissions = 5; // SECOND
}
});
}
});
Example.MainMenu = Ext.extend(Ext.app.Module, {
init : function(){
alert(Example.permissions);// I'm see 15, but want to see 5. HowI can make this var public?
}
});
If you just need some object to hold privileges and to keep variable private you should do something like this:
Example.Perm = function() {
var permissions = 15;
return {
init : function(){
Ext.QuickTips.init();
Ext.Ajax.request({
url : 'index.php?permissions=check',
success: function ( resp, opt ) {
permissions = 5; // SECOND
}
});
},
getPermissions : function() {
return permissions;
}
};
}();
alert(Example.Perm.getPermissions());
OK. I'm using last construction. But always returned `15`, because ajax-reguest executed after `alert(Example.Perm.getPermissions());`
Thanks!
Thanks for reply, Saki!
I reading Public, Private, Privileged (http://extjs.com/learn/Tutorial:Application_Layout_for_Beginners#Public.2 C_Private.2C_Privileged.3F) but there declaring public var in the `return` operator, but I need to set var in the AJAX-operator body.
Thanks.
What is that Scope all about (http://extjs.com/forum/../learn/Tutorial:What_is_that_Scope_all_about)
Application Layout for Beginners (http://extjs.com/forum/../learn/Tutorial:Application_Layout_for_Beginners)
Javascript tries to find var in nearest scope, then upper, upper, .... global.
I Am a Sinner – What About You?
Global Sourcing and Supplier Online by Dylan
|