0

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. :)

2 Answers 2

1

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'
        }
    }    
};
Sign up to request clarification or add additional context in comments.

9 Comments

Show how you're declaring it, as opposed to what the console outputs.
Test.globals.user = []; Test.globals.user.firstName and Test.globals.user.lastName.
So you don't want it to be an array, you want it to be a key/value map?
I don't care what it is. I just need those values. Can I get them somehow with the current declaration? Btw. thank you very much for helping. Appreciate it. :)
Updated OP with an example.
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.