PDA

View Full Version : Save Data from Database in Variable



Tascha
6 Nov 2009, 5:36 AM
Hello,

I want to load data from datastore and put them in a variable.




tabtitle_DataStore = new Ext.data.Store({


proxy: new Ext.data.HttpProxy({
url:'database.php',
method: 'GET'
}),
baseParams:{ip: ip_num, dataToshow: data_show, task: "GETALL"},
autoLoad: true,
reader: new Ext.data.JsonReader({
root:'results',
totalProperty:'total',
id: 'id'
},[
{name: 'hostname', type:'string', mapping:'hostname'},
{name: 'ipv4_addr', type:'string', mapping:'ipv4_addr'}

]),

sortInfo: {field: 'hostname', direction: "ASC"}

});


And now anyhow:




variable_x='hostname';


Do I have to use a datastore or something else?

Greetings

Tascha

Mthor
6 Nov 2009, 2:54 PM
could you try adding a var to the top and call that from the store. try this below


tabtitle_DataStore = new Ext.data.Store({

var variable_x = Ext.get('hostname')

proxy: new Ext.data.HttpProxy({
url: 'database.php',
method: 'GET'
}),
baseParams: {
ip: ip_num,
dataToshow: data_show,
task: "GETALL"
},
autoLoad: true,
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'total',
id: 'id'
},
[{
name: 'hostname',
type: 'string',
mapping: 'hostname'
},
{
name: 'ipv4_addr',
type: 'string',
mapping: 'ipv4_addr'
}

]),

sortInfo: {
field: 'hostname',
direction: "ASC"
}

});

Condor
6 Nov 2009, 11:14 PM
Loading a store is asynchronous, so you have to wait for the load event, e.g.

tabtitle_DataStore.on('load', function(store, records, options){
var variable_x = records[0].get('hostname');
});

Tascha
16 Nov 2009, 2:16 AM
Hi Condor!

Sorry for the late reply!



tabtitle_DataStore.on('load', function(store, records, options){
var variable_x = records[0].get('hostname');
});


Unfortunately that doesn't work...
Firebug says: variable_x is not defined

I'm trying it with a return-option, f.e.:



tabtitle_DataStore.on('load', function(store, records, options){
var variable_x = records[0].get('hostname');
return; ///////or: return variable_x;
});



Do I have to consider something else?

Thanks for help.

Greetings

Tascha

Condor
16 Nov 2009, 3:36 AM
I don't think you get the whole 'asynchronous callback' concept.

The data just isn't available in the current thread, you'll have to move all the code that uses the data to the callback method.


var x;
store.on('load', function(store, records){
x = records[0].get('x');
// you can use x here
});
// but not here

Tascha
16 Nov 2009, 3:43 AM
Oh okay, I understand.

No other options?


So I will try, thanks Condor!