Search code examples
extjsstoreextjs3jsonstore

JsonStore loads records and marks them phantom


My JsonStore is so defined:

var data_json = new Ext.data.JsonStore({
    url: '/Game/json_index',
    autoLoad: true,
    id: 'data_json',
    idProperty: 'id',
    fields: [ {name: 'id', type: 'int'}, 'name', {name:'add_date', type:'date', dateFormat: 'M$'}, 'price', 'kind', 'metacritic'],
    listeners: { 'load': function(storename, records, options){
    console.dir(this);
    }},
    writer: new Ext.data.JsonWriter()
})

the DUMP of the JSON it's receiving it's something like:

[
{"id":1,"name":"Guild Wars 2","add_date":"\/Date(1346104800000)\/","price":24.99,"kind":"MMO","metacritic":93},
{"id":2,"name":"Dark Souls: Prepare to Die Edition","add_date":"\/Date(1345759200000)\/","price":45.00,"kind":"actionrpg","metacritic":87},
{"id":3,"name":"Orcs Must Die! 2","add_date":"\/Date(1343599200000)\/","price":15.00,"kind":"action","metacritic":83}
]

the JSON is correctly decoded and the store is full of my records, but beware.. terrible things have happened!

Screenshot of the terrible thing

All of the records have been marked as phantom = true, that doesn't let me correctly use ExtJS 3.4.x store.save() functionality

I've searched thoroughly on google about this issue, and (i think) it's connected to the fact the JsonReader doesn't associate the record id to the 'id' field i'm passing. I have even specified idProperty: 'id'.

Help on this? I'm getting desperate, reading the extjs source about record creation is pure pain.


Solution

  • Try removing the:

    id: 'data_json'
    

    from your store. All the config options to a JsonStore are passed into the JsonReader that's automatically created, and that seems to be what's screwing it up.