View Full Version : Am I using datastores/readers for the correct purpose?

9 Nov 2010, 12:47 PM
I have a question on the best way to retrieve data records in ext. Thanks for any help in advance.

I am trying to make a call to my server side pages and retrieve small pieces of data. This data will be used for display purposes and javascript logic (ie html title, properties for some javascript objects). The store itself will not be used with any components.

My question is this: Do I really want to use a data store for this or is there a better way? And if a data store is the correct method, how do I directly access the records?

var infoStore = new Ext.data.JsonStore({
url: 'data_page.cfm',
baseParams: {
root_serial_id: gup('root_serial_id')
root: 'info',
autoLoad: true,
idProperty: 'SerialId',
fields: [
{name: 'SerialId', type: 'string'},
{name: 'PartNum', type: 'string'},
{name: 'SerialNum', type: 'string'}
I want to be able to access records directly after this store loads. For example, how would I directly access the value of SerialId in my data after the store loads? If this can't be done, what is the correct way to do what I'm trying to do?

Again, thanks in advance for any help.

9 Nov 2010, 1:16 PM
Well, are you retriving this data only once or you might refresh the data dynamically while the application is used? Are you loading several records or one record only that has all properties you need?


To access your data once the store is loaded:


9 Nov 2010, 1:33 PM
For the case that I'm thinking about I will only be using the data once.

And thanks for that code. I appreciate it!

9 Nov 2010, 1:44 PM
One thing I've done in my app where I only need to get to the data once is this:

url: ' someurlere ',
success: function(response, o){
var jsonObj = Ext.util.JSON.decode(response.responseText);

sorry for any typos I manually retyped that bit right there.. but anyways

In the API if you search for AJAX http://dev.sencha.com/deploy/dev/docs/

Not saying it's appropriate for your case, just saying it's something you might want to look at.. Gives you the ability to make your request right there, get the response in the success handler, and work with it

9 Nov 2010, 1:44 PM
If you will only use data once, you might consider using Ext.Ajax.request and decode your json object using Ext.util.JSON.decode.
That would be a bit more lightweight than using a store.

9 Nov 2010, 3:48 PM
Hey guys,

This is exactly what I needed. I had considered using Est.Ajax.request but I didn't know about Ext.util.JSON.decode and I figured there had to be a better way than manually parsing my response. That's why I ended up going down the path of using a reader/store.

Thanks a lot, you guys saved me a bunch of time.