vendredi 26 décembre 2014

REST Store sends "ghost" record.

I'm struggling with a REST-proxie on a TreeStore.

If I don't add a root: {} config in the store, the proxy will always send a empty "ghost"-record on first sync(). It contains all model parameters but they are empty.


If I include a copy of my real (backend) root record in the stores root-config it won't send the ghost record, but on first load() the store loads twice for some reason.


Can someone please shed some light over this, I can't be the first one with this problem, although Google makes it look so...


My Store:



Code:



Ext.define('Archive.store.Directory', { extend: 'Ext.data.TreeStore',


requires: [
'Archive.model.Directory'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
storeId: 'Directory',
autoLoad: false,
model: 'Archive.model.Directory',
root: {
id: 0,
name: '/',
games: 0,
expanded: true
}
}, cfg)]);
}
});



My Model:


Code:



Ext.define('Archive.model.Directory', { extend: 'Ext.data.Model',


requires: [
'Ext.data.field.Integer',
'Ext.data.field.String',
'Ext.data.field.Boolean',
'Ext.data.proxy.Rest',
'Ext.data.reader.Json',
'Ext.data.writer.Json'
],


fields: [
{
type: 'int',
name: 'id'
},
{
type: 'int',
name: 'idParent'
},
{
type: 'string',
name: 'name'
},
{
type: 'string',
name: 'description'
},
{
type: 'int',
name: 'games'
},
{
type: 'boolean',
name: 'leaf'
}
],


hasMany: {
model: 'Archive.model.Directory',
name: 'children'
},


proxy: {
type: 'rest',
extraParams: {
otype: 'user',
oid: 1
},
url: '/api/v1/archive/directory.php',
appendId: false,
reader: {
type: 'json',
rootProperty: 'data'
},
writer: {
type: 'json'
}
}
});





REST Store sends "ghost" record.

Aucun commentaire:

Enregistrer un commentaire