-
5 Jun 2012 6:00 AM #1
Unanswered: Global variable in sencha touch
Unanswered: Global variable in sencha touch
SALAM
I want to save a value from a web service response to use it in another view of my app.
i did this:
and when i want to use it in a store like this :Code:Ext.Ajax.request({ url: 'http://localhost:10000/Service/test/'+urtemp, success : function(response) { console.log(response); var user = eval('('+ response.responseText+ ')'); console.log(user); App.variable = user.clientID; var nv = user.clientNOM; var pr = user.clientPRENOM; if(nv !== "null") { console.log("client ID "+App.variable); Ext.Msg.alert("Bienvenue Monsieur",pr+" "+nv); Ext.getCmp('status').setTitle('Gerer votre compte'); Ext.redirect('Banking/compte'); window.location = redirect; } else {Ext.Msg.alert("Mot de passe ou login incorrecte","veuillez reeseyer");} }, failure: function(response) { Ext.getCmp('res').setValue(response.status); } });
it doesn't work.Code:Ext.regStore('storeCPT', { model: 'compte', autoLoad: true, proxy: { type: 'ajax', url: 'http://localhost:10000/Service/compteID/'+App.variable, reader: { type: 'json', } } });
how can i declare and call a global variable in sencha touch.
thank you
-
6 Jun 2012 5:37 AM #2
SALAM all.
i found a loution by adding a variable in app.js file like this
and i during the execution of the app, i add a value to this vairable like thisCode:Ext.regApplication({ name: 'App', defaultUrl: 'Home/index', launch: function() { this.viewport = new App.views.Viewport(); }, variable: '' });
App.variable = user.clientID;
but when i want to work with this variable, it's failed. here is what i did:
what can i do to fix that.Code:Ext.regStore('storeCPT', { model: 'compte', autoLoad: true, proxy: { type: 'ajax', url: 'http://localhost:10000/Service/compteID/'+App.variable, reader: { type: 'json', } } });
-
6 Jun 2012 6:54 AM #3
Try just something like this:
Without the "App."Code:url: 'http://localhost:10000/Service/compteID/'+variable,
Also, you can use a listener in your store and write console.log(App) to see what it got.
Good luck.
-
6 Jun 2012 11:22 AM #4
SALAM
thank you izak for youre response but when i removed the App, my view failed to start. and about the listener, how can i implement it ?
-
6 Jun 2012 1:25 PM #5
Hi, in your store, add this:
Good luck!Code:Ext.regStore('storeCPT', { model: 'compte', autoLoad: true, proxy: { type: 'ajax', url: 'http://localhost:10000/Service/compteID/'+App.variable, reader: { type: 'json', } }, listeners: { 'load': function(store) { console.log(store); } } });
-
6 Jun 2012 2:15 PM #6
SALAM izak
sorry but it do the same thing

-
7 Jun 2012 7:21 AM #7
Look at the console to see if your store has data and see the url too .... and rule out that possibility.


Reply With Quote