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 ?
Printable View
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 ?
Can you post a code sample of your issue please.
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
The store :
The model:Code: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 response:Code:Ext.define('app.model.Season', {
extend : 'Ext.data.Model',
fields : [ {
name : 'id',
type : 'int'
}, {
name : 'value',
type : 'int'
}, {
name : 'text',
type : 'string'
} ]
});
Code:{
"seasons": [
{
"id": 1,
"value": 1,
"text": "09-10"
}, {
"id": 2,
"value": 2,
"text": "10-11"
}, {
"id": 3,
"value": 3,
"text": "11-12"
}
]
}
This is exactly what I tried and the store had 3 records in it:
data/seasons.json is exactly this:Code: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
}
}
});
}
});
Code:{
"seasons": [
{
"id": 1,
"value": 1,
"text": "09-10"
}, {
"id": 2,
"value": 2,
"text": "10-11"
}, {
"id": 3,
"value": 3,
"text": "11-12"
}
]
}
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:
It will return zero. If you look at my post before this one, I do the getCount in the load event listener.Code:var store = Ext.create('app.store.Seasons', {});
console.log(store.getCount());
Ok, I think I understand my mistake.
I trywithout using the Ext.createCode:this.getSeasonsStore().getCount()