mercredi 17 décembre 2014

Grid store with Memory proxy calling asynchronous function from 3rd party API

I've been trying to work through a problem with populating a grid with data. I am using a memory proxy with a function that contains an asynchronous third-party API call to get the data.

The data returned by my function is formatted correctly:



Code:



returnArray={
"total":1200,
"data":{
{"id":1,"value":"blah"},
{"id":2,"value":"blah blah"}
etc....
}
}

Here is the code for my store and model:


Code:



Ext.define('result.Model',{
extend:'Ext.data.Model',
fields:['id','value']
});
resultStore=Ext.create('Ext.data.Store',{
model:'result.Model',
pageSize:30,
proxy:{
type:'memory',
enablePaging:true,
reader:{type:'json',root:'data',totalProperty:'total'}
},
listeners:{
beforeload:function(store,operation,eOpts){
var page = operation.page;
var limit = operation.limit;
var returnData=getResults(page,limit);
store.proxy.data=returnData;
}
}
});

My getResults function queries an ARCGIS using their API to get data from a geospatial database. The query is asynchronous, and by the time I get the data back, it fails to populate the

Code:



store.proxy.data=returnData;

portion of my code.

Here are the steps that I've combined in different ways to try getting this working:



  • including the 'store' in my getResults() function, and populating the store.proxy.data after my data is received.

  • suspending events first, then resuming the events once I have data.

  • calling store.sync() in my store's "load" listener.

  • calling store.load() (this populates my grid with data, and paging appears to work, but I end up in an infinite loop.

  • calling store.loadData and populating the grid directly (works but paging doesn't update)


Any recommendations?



Grid store with Memory proxy calling asynchronous function from 3rd party API

Aucun commentaire:

Enregistrer un commentaire