View Full Version : Loading json to store for controls to consume

25 May 2010, 12:24 PM

There must be a "one-liner" or almost generic implementation for this...!

I want to call (GET or POST):


It will return something like:

companyId: '2',
userName: 'username1',
realName: 'realname 2',
isActive: '1',
email: '[email protected]',
createdDate: '2009-11-10T00:00:00',
modifiedDate: '2010-01-14T21:27:31.383'
companyId: '2',
userName: 'username2',
realName: 'realname2',
isActive: '1',
email: '[email protected]',
createdDate: '2010-01-14T14:10:06.293',
modifiedDate: '2010-01-14T21:12:06.500'

Can I load a store automatically (preferably a JsonStore) just sending the fields definition in to a generic function? I can't seem to get the actual loading to work because the url will not take the query parameters.


25 May 2010, 4:01 PM
In order to send params into the Ajax request you should do something like this:

params : {param1:1,param2:2}

try the "store.loadData(jsonData)" to load local data into your store.

25 May 2010, 10:00 PM
Ok. I'll give that a try.

Another question though. Will it wait synchronously for the store to load or will it move on?

25 May 2010, 10:37 PM
Your suggestion works fine.

I see that it's loading asynchronously.

Is there a good way of waiting for the stores to be loaded before creating the UI? As I'm doing it now is to create an empty store for the control with the same field set and add it to the container. When the store enters the callback function call bindStore of the control which gives me some problems knowing when all is actually loaded. The only other way I can think of is to in the store callback call a function to see whether all stores are loaded or not and if they are then load the UI.

25 May 2010, 10:40 PM
Yes, you should indeed use the load callback (or load event).

ps. I don't see a reason to wait until all stores are loaded before creating the UI. Why not do these things in parallel?

25 May 2010, 11:40 PM
The stores load in parallel but I can't create for instance the ListView without a store or empty data. It will complain about some length property on an object not initiated and I like the notion of creating the UI in one go to keep it simple.

Is there a better way maybe you can write a small flow on how to do it? I'm all ears!

25 May 2010, 11:44 PM
you can - just configure it with a defined store, the load can be done later (or use autoLoad:true)

26 May 2010, 1:44 AM
So I can define the store, apply it to the control and set autoLoad: true. Where do I the set params?

A very small example maybe?

26 May 2010, 1:47 AM
Like this?

autoLoad: {param1:1, param2:2},

or maybe:

autoLoad: {params:{param1:1, param2:2}},

26 May 2010, 2:01 AM
Refer the documentation:
If data is not specified, and if autoLoad is true or an Object, this store's load method is automatically called after creation. If the value of autoLoad is an Object, this Object will be passed to the store's load method.

so second one is correct

26 May 2010, 3:00 AM
Yeah, that's where I got it from :).

Thanks all for your help. I think I'll be able to figure it all out now.