PDA

View Full Version : Not able to get values from app.js to other panel (It gives "undefined")



ppurohit
20 May 2013, 12:06 AM
Hello Everyone...

Following is my launch function of app.js



launch: function() {
// Destroy the #appLoadingIndicator element
Ext.fly('appLoadingIndicator').destroy();

var urlstore = Ext.getStore('Urls');


urlstore.load();

var count=urlstore.getCount();
var max=count;
if(count>2)
{
urlstore.removeAt(1);
}
urlstore.sync();
record=urlstore.getAt(1);
urlstore.load().each(function(record) {
console.log(record.getData());
});

console.log('Count: ' + urlstore.getCount());
servername = record.data.serverNameTextField;
port = record.data.portTextField;
contextRoot = record.data.contextTextField;
var myUrl;
// console.log(servername);
myUrl="http://"+servername+":"+port+"/"+contextRoot;


console.log(myUrl);
//Initialize the main view
Ext.Viewport.add(Ext.create('MobileClient_HTML5.view.Main'));
Ext.Viewport.add(Ext.create('MobileClient_HTML5.view.Setting'));
Ext.Viewport.add(Ext.create('MobileClient_HTML5.view.MainMenu'));
Ext.Viewport.add(Ext.create('MobileClient_HTML5.view.Account'));




},

I have created 1 model and 1 store for using and storing values..
Following is my store (urls.js)

Ext.define('MobileClient_HTML5.store.Urls', {
extend: 'Ext.data.Store',

config: {
model: 'MobileClient_HTML5.model.Url',
autoLoad: true,

proxy: {
type: 'localstorage',
id : 'myUrlKey'
}
}
});

following is my model (url.js)
Ext.define('MobileClient_HTML5.model.Url', {
extend: 'Ext.data.Model',
requires:['Ext.data.identifier.Uuid'],
config: {
identifier:'uuid',
fields: [
'serverNameTextField',
'portTextField',
'contextTextField'
]
}
});


I have successfully saved the servarname+ port name + context path inside the the variable "myurl" and displaying it on the console. but i am not able to get this myurl on the other panel.. it gives the Output as "Undefined." :-/

I am stucked.... Please help.... Thanks..

existdissolve
20 May 2013, 4:04 AM
With "var", you've made that variable local to the launch() method. Either make it global or set it as a property of your application.

ppurohit
20 May 2013, 10:28 PM
Hey,

Thanks for your help...
Now I have removed it from launch function and put it at the top of app.js. but still the problem remains the same.

Basically, I am have to store different URL's in store and then use them inside my app on different tabs..

can you please tell me the right way of making a variable globally accessible inside app?

Please help!! thanks

existdissolve
21 May 2013, 5:27 AM
I typically create a globals class where I can store values, objects, etc. that I want to make available across my app:


Ext.define('MyApp.Globals', {
singleton: true,
constructor: function( config ) {
this.initConfig( config );
return this;
},
config: {
urls: {
somekey: 'someurl',
anotherkey: 'anotherurl',
...
}
}
})

Ext.application({
requires: [
'MyApp.Globals',
...
]
});


The idea being that you could create a key in some object for each unique url you need, and then simply access that url from this object as needed elsewhere in the app.