所以,当我提出console.log(Test.globals.user)
时,我得到了这个:
[id: "1", first_name: "MyFirstName", last_name: "MyLastName"]
如何获取名字和姓氏的值?我试过这个:
Test.globals.user.first_name //undefined
Test.globals.user[first_name] //error - no first_name variable provided
Test.globals.user["first_name"] //undefined
谢谢。 :)
答案 0 :(得分:1)
Ext的做法是拥有一个单例类来保存全球的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);
});
非Ext示例
var Test = {
globals: {
user: {
first: 'Foo'
}
}
};
答案 1 :(得分:0)
你能试试Test.globals.user [1] .first_name吗?