PDA

View Full Version : JsonStore - Proper Usage



Comister
19 Jul 2010, 1:58 PM
Hi,

I just started to investigate and try out in u're beautiful framework.
Now i am at a point where i am not sure how to proceed, i have tried to setup the following JsonStore object which should retrieve data automatically right after the object created ( i believe ):



store: new Ext.data.JsonStore({ /* implement request data by json from server */
model: 'MenuEntry',
sorters: 'Type',

getGroupString : function(record) {
return record.get('Type');//[0];
},

//proxy: new Ext.data.HttpProxy({url:'/iphone/test.json'}),
url : '/iphone/test.json',
method : 'GET',
root: 'monday',
storeId : 'something',
//fields : ['Menu','Type'],
//autodestroy : true,
autoLoad: true,

listeners: {
loadexception: function() {
console.log('load failed -- arguments: %o', arguments);
}
}
})


The json file for testpurposes looks like the following:



{
monday :
[
{Menu: 'Irgendwas', Type: 'fatale'},
{Menu: 'Was Anderes', Type: 'fatale'},
{Menu: 'Noch was', Type: 'fatale2'}
[
}


But i an error in the Devloperconsole of Chrome:


Uncaught TypeError: Cannot call method 'indexOf' of undefined

In the mentioned line following code is present:



urlAppend : function(url, s){
if(!Ext.isEmpty(s)){
return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
......


It seems the parameter url is empty, but i have currently no clue where this reference is passed through, to tough object inheritance to examine for me.

Anybody a clue ?
Maybe i am using the object totally wrong and also some time passed since i used javascript.

Thanks for every help or hint !

Comister
20 Jul 2010, 9:49 AM
Either my question is very stupid or the problem is not that easy ?

Thank you

Animal
20 Jul 2010, 9:57 AM
So when you break on that line and walk back through the call stack, where does the undefined value start?

Comister
20 Jul 2010, 11:13 AM
Hi Animal,

Following results of my investigations:

1. JsonStore seems to create a AjaxProxy automatically if autoLoad = true
2. The proxy is supposed to work with arguments, in that case the arguments are empty
3. That means the URL in the definition above will not be included into the arguments of the automatically created proxy

I assume the following, not tried yet, if i manually define a AjaxProxy within the JSONStore the problem is gone, what do u think ?
I am a little bit struggeling with that :-) , sorry ...
At least i was already able to make it bi langual based on the browser language ( *proud* )

The next question would be, if i have 5 different lists accessible through a carousel ( this is already working with inlinedata, but with 5 different stores :-/ ),, all those 5 are accessing the same json source, only the root is different, would it be the best approach to define 5 different stores as well or how would be the best way/approach to achieve that ?

Comister
20 Jul 2010, 12:47 PM
Ok, seems my assumption was right, after setting the proxy in the store autoLoad also works fine, i get the data !
Unfortunately that seems to be not documented or i have not found it, anyway, its working !

Maybe somebody have a hint for me how to fill 5 different list with one Store by using 5 different Roots ?

fyi, the store object is now defined as follows ( url went from the store into the proxy, the root was moved into the reader within the proxy, thats it ):



store: new Ext.data.JsonStore({
model: 'MenuEntry',
sorters: 'Type',
getGroupString : function(record) {
return record.get('Type');
},
storeId : 'something',
autoLoad: true,
proxy: {
type: 'ajax',
url : '/iphone/test.json',
reader: {
type: 'json',
root: 'monday'
}
},
listeners: {
loadexception: function() {
console.log('load failed -- arguments: %o', arguments);
}
}
}


Thanks a lot

Comister
21 Jul 2010, 11:28 AM
Any tipps, hints ?

Thank you