PDA

View Full Version : Problem while loading a JsonStore



Manuel Esteban
17 Jul 2009, 4:53 AM
Hello.


After having used the search engine, I still have a problem loading a store.
I got a json store that request my server.
The request works and return some json data, but while listenning the result, this request seems not to work.

My code :


DirStore = new Ext.data.JsonStore({
url: 'core/index.php',
root: 'result',
totalProperty: 'nb_result',
idProperty: 'dir',
baseParams: {request_id:1, action:'DirContent'},
});

DirTpl = new Ext.XTemplate(
'<div>Ceci est un test !!!! </div>',
'<tpl for=".">',
'directory',
'</tpl>'
);

DirView = new Ext.DataView({
region: 'center',
itemSelector: 'div.custom-checkbox',
style:'overflow:auto;border-right:1px solid #dadada',
multiSelect: false,
singleSelect: true,
loadingText: 'Loading...',
overClass:'custom-checkbox-over',
selectedClass: 'custom-checkbox-selected',
store: DirStore,
tpl: DirTpl
});

DirInfos.addItem({
xtype:'panel',
anchor: '100%', // anchor width by percentage
layout:'fit',
autoHeight: true,
items:[
DirView
]
});

DirStore.load({
params:{}, callback:function(rec, opt, res){
console.log(rec); // []
console.log(opt); // Object params=object
console.log(res); // false
}
});The Json generated with PHP :


{"result":[{"dir":"."},{"dir":".."},{"dir":"browser.rar"},{"dir":"ver_1_0.rar"}],"nb_result":4}
The Json seems good, so I probably made a mistake in my store code.. but I don't find where.
Could someone help me to understand what's wrong ?

Thank you.

tryanDLS
17 Jul 2009, 12:33 PM
First of all, simplify to debug - no xtemplate or dataview, just get a store to load. I didn't try this at all, but my thought would be that pointing idProperty at something that has values like '.' and '..' might be a problem. I would suggest using ext-all-debug.js and setting break points in the store load process to see what's causing it to break.

Manuel Esteban
17 Jul 2009, 12:58 PM
Thank you for your answer.

I skip the "." and ".." data on the json returned by the server.
The problem is still there and data return by the server is now :


{"result":[{"dir":"browser.rar"},{"dir":"ver_1_0.rar"}],"nb_result":2}


I made a new test with this javascript :

Ext.onReady(function(){
DirStore = new Ext.data.JsonStore({
url: 'core/index.php',
root: 'result',
totalProperty: 'nb_result',
idProperty: 'dir',
baseParams: {request_id:1, action:'DirContent'},
});
DirStore.load({
params:{}, callback:function(rec, opt, res){
console.log(rec);
console.log(opt);
console.log(res);
}
});
});


I still have the problem.
the "console.log(res);" return a false.
I don't understand what's missing. That's probably something stupid that I forgot, but... the request is done but the store isn't loaded