Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing static properties in Sencha Touch

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

like image 514
nsg Avatar asked Dec 13 '12 13:12

nsg


2 Answers

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;
    }
});
like image 133
Ram G Athreya Avatar answered Nov 20 '22 09:11

Ram G Athreya


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]);
    }
});
like image 25
user601752 Avatar answered Nov 20 '22 10:11

user601752