views:

706

answers:

1

Please help me with this problem. I'm new in extJs and i need a little help. I have this code

Ext.onReady(function() {
 var datesStore = new Ext.data.JsonStore({
  start : 'StartTableDate',
  end : 'FinishTableDate',  
            autoLoad : true,
            proxy : new Ext.data.HttpProxy({
                url : 'dates.json',
                method:'GET'
            }),
            fields : [
                // 2 mandatory fields
                {name:'StartTableDate'},
                {name:'FinishTableDate'}
            ]
        });

// i want to pass to variable start si end the values from JSON
var start = 'StartTableDate';
var end = 'FinishTableDate';
A: 

If I understand you correctly, you want to get the values from the first record of a JsonStore and assign them to variables. If that's the case, then I think you want an event handler:

var datesStore = new Ext.data.JsonStore({
            proxy : new Ext.data.HttpProxy({
                url : 'dates.json',
                method:'GET'
            }),
            fields : ['StartTableDate','EndTableDate']
        });
datesStore.on('load',function(dataStore,records,options) {
    if (records.length > 0) {
        var start = records[0].get('StartTableDate');
        var end = records[0].get('FinishTableDate');
     }
},this);
Mike Sickler
Ok, this is a great answer ... but i have one stupid question.After your code if i writeExt.MessageBox.alert('Value1', start);it displays an empty value. How can i get the values start and end?Thanks
tinti
Is the alert after the event handler or inside it? It would need to be inside it. Try breakpointing in Firebug inside the event handler to see what the value of 'records' is.
Mike Sickler
The alert it's outside the event handler. So you say that start and end variables has non empty values only in handler?I want to use the values outside this handler ... it is possible?Thanks
tinti
The store loads asynchronously, so it if you try to evaluate the variables right after the handler is declared, then they probably will be null because the store hasn't finished loading. You need to use the values from within the event handler.
Mike Sickler
I've updated the code to declare the variables inside the event handler. Sorry if that misled you...
Mike Sickler