user1509885
user1509885

Reputation:

How to use values from this array? Ext-JS 4

So, when I put console.log(Test.globals.user) I get this:

[id: "1", first_name: "MyFirstName", last_name: "MyLastName"]

How can I get values of first and last name? I've tried this:

Test.globals.user.first_name //undefined
Test.globals.user[first_name] //error - no first_name variable provided
Test.globals.user["first_name"] //undefined

Thank you. :)

Upvotes: 0

Views: 136

Answers (2)

srknori
srknori

Reputation: 166

can you try Test.globals.user[1].first_name?

Upvotes: 0

Evan Trimboli
Evan Trimboli

Reputation: 30092

The Ext way of doing it would be to have a singleton class to hold global, app wide vars:

Ext.define('Test.globals', {
    singleton: true,

    user: {
        id: 1,
        first: 'Foo',
        last: 'Bar'
    }
});

Ext.onReady(function(){
    console.log(Test.globals.user.first);
});

Not Ext example

var Test = {
    globals: {
        user: {
            first: 'Foo'
        }
    }    
};

Upvotes: 1

Related Questions