0

I am facing a problem in sencha while mapping Ext.data.JsonStore model using Ext.data.JsonReader.

Json response from server (server model):

{"rows":[{"id":1,"firstname":"Bill"},{"id": 2,"firstname":"Ben"}]}

Model used in Json Store:

Ext.regModel( 'mycabinet', {
fields: [ 
{ name : 'DeviceId', type: 'int' },
'CabinetName']
});

json Reader code:

var iccDeviceReader = new Ext.data.JsonReader({
// metadata configuration options:
idProperty: 'id',
root: 'rows',
fields: [
{name: 'CabinetName', mapping: 'firstname'},
{name:'DeviceId',mapping:'id'}
]
});

json store code:

app.iccDS = new Ext.data.JsonStore( {
model : 'mycabinet',
sorters  : 'CabinetName',
getGroupString : function(record) { return record.get('CabinetName')[0]; },
proxy    : {
type: 'ajax',
url : '/icc/js/data.js',
reader:iccDeviceReader
},
autoLoad: true
} );

I am expecting that "mycabinet" model will get populated with "server model". However, mapping doesnt occur. I even tried using convert without any success(name:'DeviceId',mapping:'id',convert: function(v){return v.id;})

Any help will be highly appreciated. Thanks

nuzahat
  • 1
  • 1

2 Answers2

0

Remove the "fields" option from your Reader and change 'CabinetName' to {name: 'CabinetName', mapping: 'firstname'} in your model config. Also, idProperty should also go into your model config.

0

Following code solved my problem...

Ext.regModel( 'mycabinet', {
fields: [ 
{ name : 'DeviceId', type: 'int',mapping:'id' },
{name: 'CabinetName', mapping: 'firstname'}]
});

app.iccDS = new Ext.data.JsonStore( {
model : 'mycabinet',
sorters  : 'CabinetName',
getGroupString : function(record) { return record.get('CabinetName')[0]; },
proxy    : {
type: 'ajax',
url : '/icc/js/data.js'
},
autoLoad: true
} );

I am not using jsonReader anymore.

nuzahat
  • 1
  • 1