PDA

View Full Version : [CLOSED] Bug with store / ajax proxy ????



jairok
15 Oct 2011, 5:28 AM
Hi,

Maybe found a bug in store.. very annoying...

I made a store with ajax proxy, json format.

When I load the store, the callback has 3 items in records arg, but when I look at the store, he's empty.

Anyone can help ?

Jamie Avins
15 Oct 2011, 8:36 AM
Can you post a code sample of your issue please.

mitchellsimoens
15 Oct 2011, 7:17 PM
This usually means that your fields don't match what is being returned or your reader isn't setup properly so code for your store and model and the response returned is what is needed to help you

jairok
16 Oct 2011, 3:09 AM
The store :


Ext.define('app.store.Seasons', { extend : 'Ext.data.Store',
model : 'app.model.Season',
requires : [ 'app.model.Season' ],


proxy : {
type : 'ajax',
url : 'data/seasons.json',
reader : {
type : 'json',
root : 'seasons'
}
},


autoLoad : true
});

The model:


Ext.define('app.model.Season', {
extend : 'Ext.data.Model',
fields : [ {
name : 'id',
type : 'int'
}, {
name : 'value',
type : 'int'
}, {
name : 'text',
type : 'string'
} ]
});


The response:


{
"seasons": [


{
"id": 1,
"value": 1,
"text": "09-10"
}, {
"id": 2,
"value": 2,
"text": "10-11"
}, {
"id": 3,
"value": 3,
"text": "11-12"
}
]
}

mitchellsimoens
17 Oct 2011, 7:47 AM
This is exactly what I tried and the store had 3 records in it:


Ext.define('app.model.Season', {
extend : 'Ext.data.Model',
fields : [ {
name : 'id',
type : 'int'
}, {
name : 'value',
type : 'int'
}, {
name : 'text',
type : 'string'
} ]
});

Ext.define('app.store.Seasons', {
extend : 'Ext.data.Store',
model : 'app.model.Season',
requires : [ 'app.model.Season' ],

proxy : {
type : 'ajax',
url : 'data/seasons.json',
reader : {
type : 'json',
root : 'seasons'
}
},


autoLoad : true
});

Ext.setup({
onReady: function() {

var store = Ext.create('app.store.Seasons', {
listeners : {
load: function(store) {
console.log(store);
console.log(store.getCount()); //returns 3
console.log(store.data.getCount()); //returns 3
}
}
});
}
});

data/seasons.json is exactly this:


{
"seasons": [


{
"id": 1,
"value": 1,
"text": "09-10"
}, {
"id": 2,
"value": 2,
"text": "10-11"
}, {
"id": 3,
"value": 3,
"text": "11-12"
}
]
}

mitchellsimoens
17 Oct 2011, 7:49 AM
I just had a thought... did you try to get the count of the store after you created the store or in the load event?

Even though it is localstorage and autoLoad is true, there is still time needed for the load to happen so if you did this:


var store = Ext.create('app.store.Seasons', {});
console.log(store.getCount());

It will return zero. If you look at my post before this one, I do the getCount in the load event listener.

jairok
17 Oct 2011, 9:50 PM
Ok, I think I understand my mistake.

I try
this.getSeasonsStore().getCount()
without using the Ext.create