How do you create static fields in a class and then access them from outside of that class in Sencha Touch 2?
For example I have created a simple singleton with a single static:
Ext.define('App.util.Config', {
singleton: true,
statics: {
url: {
USER: 'http://localhost:3436/api/user'
}
},
config: { },
constructor: function (config) {
this.initConfig(config);
this.callParent([config]);
}
});
I cannot access the USER field using App.util.Config.url.USER but with App.util.Config.self.url.USER. Looking at a sample on the Sencha docs, it appears that I should be able able to access the field in the former way:
See Statics Section in this link and how they access the Computer.InstanceCount field
I think this is what you want
Ext.define('App.util.Config', {
singleton: true,
statics: {
url: {
USER: 'http://localhost:3436/api/user'
}
},
config: { },
constructor: function (config) {
var user=this.self.url.User;
}
});
I realize that this is an old questions, but I stumbled upon it when looking for something else.
I believe that the problem is the use of singleton:true
. When this is used, then everything is static and there is no need to define the property explicitly as static.
The following should be the correct use:
Ext.define('App.util.Config', {
singleton: true,
url: {
USER: 'http://localhost:3436/api/user'
},
config: { },
constructor: function (config) {
this.initConfig(config);
this.callParent([config]);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With