PDA

View Full Version : STORE not load!!!



GusDEx
25 Nov 2010, 11:18 AM
Hi, I have a problem with Store, and find examples everywhere that supposedly work and compare with mine and can not find the error, someone can give me a hand ... I appreciate it ...

The issue is I can not load the store, my final idea is to load a combo, but I realized that does not call the php!!

Here is simplified:

JS

var storeCL = new Ext.data.JsonStore({
url: 'sdcBuscL.php',
root: 'data',
totalProperty: 'totalCount',
fields: [ 'idCateg', 'CategNom' ]
});

storeCL.load();

var n = storeCL.getTotalCount();
alert(n); // Return 0 !!!!! Must Return 2


PHP

echo "{success: true, totalCount: 2, data: [ { idCateg: 1, CategNom: 'Pepe1' }, { idCateg: 2, CategNom: 'Pepe2' } ] }";
exit;

fay
25 Nov 2010, 11:31 AM
If you read the documentation you'll see that the load() method is asynchronous so you can't just call getTotalCount() after calling load(). I'm sure this was answered earlier today!




Notes:

Important: loading is asynchronous! This call will return before the new data has been loaded. To perform any post-processing where information from the load call is required, specify the callback function to be called, or use a a 'load' event handler (http://dev.sencha.com/deploy/dev/docs/output/Ext.util.Observable.html#Ext.util.Observable-listeners).

EDIT: Also, it's best not to use alert() for debugging, use FireBug or console.log().

scusyxx
25 Nov 2010, 12:58 PM
Try this.


storeCL.load({
callback:function(r, options, success) {
if(success)
alert(storeCL.getTotalCount());
}})


Hi, I have a problem with Store, and find examples everywhere that supposedly work and compare with mine and can not find the error, someone can give me a hand ... I appreciate it ...

The issue is I can not load the store, my final idea is to load a combo, but I realized that does not call the php!!

Here is simplified:

JS

var storeCL = new Ext.data.JsonStore({
url: 'sdcBuscL.php',
root: 'data',
totalProperty: 'totalCount',
fields: [ 'idCateg', 'CategNom' ]
});

storeCL.load();

var n = storeCL.getTotalCount();
alert(n); // Return 0 !!!!! Must Return 2


PHP

echo "{success: true, totalCount: 2, data: [ { idCateg: 1, CategNom: 'Pepe1' }, { idCateg: 2, CategNom: 'Pepe2' } ] }";
exit;

GusDEx
25 Nov 2010, 1:17 PM
Ok, I understand. Thank you very much for responding, Fay