PDA

View Full Version : JsonStore manually loading data - FAIL!



vargadanis
17 Nov 2009, 4:25 AM
Hi,
I am trying to manually load data into a json store that is hooked up with a combobox.
So I try to do it after the component is rendered so I have something like this:


/*...*/
listeners: {
render: function(){
var mydata = [ [solarSystemID, solarSystemName] ];
this.getStore().loadData(mydata);
}
}
The solarSystemID and solarSystemName variables are defined somewhere else but they are accessible. At least this is what console.log() said.
Now the ERROR:


g is undefined
http://localhost/allytrade/ext/ext-all.js
Line 7

As far as I know loadData will need the data structure of the reader. In this case this is simple:

var systemStore = new Ext.data.JsonStore({
autoDestroy: true,
url: 'ajax.php?action=system',
storeId: 'systemStore',
root: 'systems',
idProperty: 'solarSystemID',
fields: ['solarSystemID', 'solarSystemName']
});So I am guessing that I have the proper structure, don't I?
If so, what could be the problem?

Condor
17 Nov 2009, 4:48 AM
Your data doesn't match your JsonReader config.

The data should be:

var mydata = {
systems: [{
solarSystemID: 123,
solarSystemName: 'xyz'
}]
};

vargadanis
17 Nov 2009, 6:07 AM
Dang it... O_o
I am guessing my assumptions are gonna get even worse as I dip into the more complicated stuff but ehh, who cares? Let's go ahead and hope I can figure everything out :)
Thank you Condor!

This rises the next question. I have this combo box and I'd like it to display the manually inserted data. I don't really know how to do it, any tips?

Condor
17 Nov 2009, 6:13 AM
This rises the next question. I have this combo box and I'd like it to display the manually inserted data. I don't really know how to do it, any tips?

How is the combobox configured? Do you have matching data to fill the combobox store?

vargadanis
17 Nov 2009, 6:27 AM
I have made a paste with the combobox config and the data store it uses:
http://pastebin.com/m54614b6d

I hope it helps.
Matching data? What do you mean by that?

nicobarten
17 Nov 2009, 7:08 AM
I guess he means the right valueField and displayField...

Condor
17 Nov 2009, 7:27 AM
It's a bit strange to fill the combobox on render. Why not when the store was created (use the 'data' config option).

You probably also want to call setValue to set the combobox to an entry in the list.

vargadanis
18 Nov 2009, 1:43 AM
Hi,

after a very very long discussion with a friendly guy on IRC, I cleared everything up and it works perfectly now. In a few hints what I had to do:



had to use remote sorting, for that:

I needed the server side script handle the POST[query] variable as the contents of the combo box send the data in that
had to modify the server side script the chk if it was given a string or a integer and return the appropriate value accordingly
set mode: 'remote' in config option of the combo box

in order to load a predefined dataset into the combo box by the ID of the data I had to

create an event listener on the combo box to load the data with the appropriate paramteres: this.store.load({ params: { query: idValueVar} });
create a function in which I get the combo box, set it's value and remote the data store 'load' event listener
set up the data store's load event listener to point to the function I created in step 2-2


I was so happy that it worked yesterday that I quickly created a 40min. long Video Tutorial with my crazy accent. I am in the process of uploading it now and should be available shortly. Basically I did and explained all the step up there...