PDA

View Full Version : Problem loading data into a Json store



r_honey
15 Feb 2010, 6:41 AM
Following is the code for my Json store:



new Ext.data.JsonStore( {
// store configs
autoDestroy: true,
// reader configs
root: 'files',
idProperty: 'id',
fields: [ 'id', 'text', 'qtip' ]
})


Please note that the Store should not load its data from some url, rather I need to manually load data into the store on some actions being performed somewhere else on the form.

Here is what I do when those actions are performed:


var nodes = Ext.decode(response.responseText);
var files = [];
for (i = 0; i < nodes.length; i++) {
if (nodes[i].leaf) {
files.push(nodes[i]);
}
}
mystore.loadData(files, false);


This always generates the following error:
g is undefined
http://localhost:8080/extjs/3.1.0/ext-all.js?u
Line 7

Any ideas of what I am doing wrong would be greatly appreciated.

fay
15 Feb 2010, 6:54 AM
Are you sure that the data structure in "nodes" is correct?

Use ext-all-debug.js, FireFox + FireBug, put a breakpoint at loadData and step into the code.

r_honey
15 Feb 2010, 7:32 AM
Here's the output of console.log(Ext.encode(files)):



[{"id":"D:/xampp/htdocs/subdir/.buildpath","text":".buildpath","qtip":"Type: File<br />Last Modified: Feb 13, 2010, 3:14 pm<br />Size: 174 B","cls":"file","leaf":true},{"id":"D:/xampp/htdocs/subdir/.htaccess","text":".htaccess","qtip":"Type: File<br />Last Modified: Feb 14, 2010, 1:42 am<br />Size: 4 KB","cls":"file","leaf":true},


The output is partial that should be sufficient for analysis.

fay
15 Feb 2010, 7:41 AM
And did you...


Use ext-all-debug.js, FireFox + FireBug, put a breakpoint at loadData and step into the code.

Also, try initially setting data to empty:


new Ext.data.JsonStore( {
// store configs
autoDestroy: true,
// reader configs
root: 'files',
idProperty: 'id',
fields: [ 'id', 'text', 'qtip' ],
data:[] // <--
});

r_honey
15 Feb 2010, 8:18 AM
Also, try initially setting data to empty:

});[/CODE]

Well thanx, a variation of what you said worked. I had to set the data initially as:
data:{files:[]}

and later, in loadData as:
store.loadData({files:files},false);

And it works perfectly now. Thanx again.

radubrehar
15 Feb 2010, 8:21 AM
Your data should have the following format:


{ files: [ ] }


I see you are directly trying to load an array, but in fact you should load an object with the root property named "files", which should point to the array you are trying to load.