PDA

View Full Version : Reading Constants File



chichasonu
22 Dec 2015, 11:04 PM
Hi,
I have a singleton Constants File as below

Ext.define('MyApp.Constants',{

test:'1212'});

When i am trying to read in the below manner i am getting the value as undefined

var constant='test'
MyApp.Constants.constant;(This is coming as undefined)
Can some one please help me with the same
Thanks in Advance

jdkhamba
23 Dec 2015, 1:10 PM
You haven't specified the class as singleton. You need singleton :true for that.

chichasonu
23 Dec 2015, 8:40 PM
Hi,
I have Already tried the Same.But Still its not working
Please find the fiddle below


https://fiddle.sencha.com/#fiddle/1316

jdkhamba
24 Dec 2015, 4:42 AM
"myConstant" variable itself is not defined within the singleton class :)

https://fiddle.sencha.com/#fiddle/131l

chichasonu
25 Dec 2015, 7:11 PM
Hi,
The Key comes Dynamically.How can we get the Value if it is coming Dynamically.
Can you please help me with dynamic key reading.
Thanks in Advance.

tristan.lee
29 Dec 2015, 9:32 AM
It's coming dynamically from where? Unless it's defined on the class it's going to be undefined...

Assuming you have the following, what is your expected result?

Ext.define('Fiddle.MyConstants', {
singleton: true,
test: 'Testing'
});

chichasonu
29 Dec 2015, 11:03 AM
Thanks for the Reply
Key Comes Dynamically.
In the example You Provided.key test comes dynamically.
I need the Value of the Key test from Constants file.
Can you please help me achieving This

tristan.lee
29 Dec 2015, 11:25 AM
In my example, the key test is coming from the MyConstants class. It's not being dynamically set.

Are you saying that you need to dynamically set a test key on the MyConstants class that can later be referenced?

tristan.lee
29 Dec 2015, 11:28 AM
I think I might understand what you're asking for now...


Ext.define('MyApp.Constants', {
singleton: true,

test: '1212'
});


var constant = 'test';


Ext.application({
name: 'MyApp',
launch: function() {
console.log(MyApp.Constants[constant]);
}
});

chichasonu
30 Dec 2015, 9:20 PM
Thanks.....it Worked...:)