I’m creating and loading a store just fine. However, when I attempt to retrieve a record from the first model instance, using the first() method, it fails.
Here’s the code:
var getCaseId = function(){
var csId;
//form url
var getCaseIdStore = Ext.create('Roa.store.district.Requests', {
model: 'Roa.model.district.Requests',
proxy: {
type: 'ajax',
url : 'http://localhost:8080/roa/MongoDataService/requests?etc',
method: 'GET',
reader: {
type: 'json',
root: 'requests'
}
},
autoLoad: true
});//end create store
console.log('request store created');
getCaseIdStore.load({
scope: this,
callback: function(records,operation,success){
if(success){
//var req = getCaseIdStore.first();
//var csId = req.get('caseId');
//console.log('csId==>'+csId);
//return csId;
}//end if
}//end callback
});//end store load
var req = getCaseIdStore.first();
if (req != undefined){
csId = req.get('caseId');
console.log('return csId==>'+csId);
return csId;
}
else{
console.log('your attempt failed');
}
};//end function
Please advise good folks.
-TU
Loading process is asynchronous. You can’t just call it and then try to get the first record – move your .first() call into store loading callback as you have it in commented out lines. These lines should work just fine.