PDA

View Full Version : How to configure a JsonStore after it's loaded?



cwolves
20 Oct 2010, 6:32 AM
I'm just looking for a simple example of how to configure a JsonStore after it's been created. Or how to set the store on a comboBox after it's been created.

Thanks :)

Condor
20 Oct 2010, 6:37 AM
The fact that you want this is already questionable.

Could you explain why?

cwolves
20 Oct 2010, 6:52 AM
Because I do? :)

Really though, I have compressed data streaming in over a comet connection that's coming in after a form has been created. The structure of the data coming in is variable (in that I don't have a list of all the fields)...

So flow:

- Form is created for visual purposes
- Structure & Data comes in
- Need to populate combo box

I don't really care how the last step is done, I figured either of the methods I'd listed would work though.

Condor
20 Oct 2010, 6:55 AM
No need to create a different store for that.

Just load the existing store with the new data (but include a metaData property in the data that contains the new reader config).

ps. While this is the preferred method, your original method would also work if you used combobox.bindStore().

cwolves
20 Oct 2010, 8:20 AM
Thanks for the response. I'm trying the code from the example and nothing is showing up in the comboBox (the obj is directly from http://dev.sencha.com/deploy/dev/docs/source/JsonReader.html#cls-Ext.data.JsonReader):


store.loadData({metaData: {"idProperty": "id","root": "rows","totalProperty": "results","successProperty": "success","fields": [{"name": "name"},{"name": "job", "mapping": "occupation"}],"sortInfo":{"field": "name","direction": "ASC"},"start": 0,"limit": 2,"foo": "bar"},"success": true,"results": 2000,"rows": [{ "id": 1, "name": "Bill", "occupation": "Gardener" },{ "id": 2, "name": "Ben", "occupation": "Horticulturalist" }]})

Any ideas? Thanks :)

cwolves
20 Oct 2010, 9:25 AM
Okay, I can't figure out a simple example:


var foo = new Ext.form.ComboBox({
renderTo: document.body,
store:new Ext.data.JsonStore({
reader:new Ext.data.JsonReader()
}),
valueField: 'value',
displayField: 'name'
});

foo.store.loadData({
metaData: {
fields: [
{name : 'name'},
{value : 'value'}
],
root:'rows'
},
'rows': [
{ value: 1, name: 'Bill'},
{ value: 2, name: 'Ben'}
]
});

The store now has data in it, but it's not showing up in the select box.

help? :)

Condor
20 Oct 2010, 11:37 AM
Corrections:

var foo = new Ext.form.ComboBox({
renderTo: document.body,
store:new Ext.data.JsonStore({
reader:new Ext.data.JsonReader({fields: []})
}),
valueField: 'value',
displayField: 'name',
mode: 'local'
});

foo.store.loadData({
metaData: {
fields: [
{name : 'name'},
{name : 'value'}
],
root:'rows'
},
'rows': [
{ value: 1, name: 'Bill'},
{ value: 2, name: 'Ben'}
]
});