-
13 Jan 2010 2:45 AM #1
Problem with mapping in JsonStore
Problem with mapping in JsonStore
Hi everyone,
I have the following problem. I'm trying to consume ajax response in the folowing JSON format:
Javascript code responsible for consuming this response looks like this:Code:{ "message": "Something good happened on the server!", "data": [ { "created_at": "2009-12-18 17:04:12", "abstract": "Some abstract", "state": { "id": 5, "name": "Published" }, "title": "Some title" }] }
When I do not make mapping for "state" field everything is OK, but with above mapping loading store loads no records without any error.Code:var store = new Ext.data.JsonStore({ proxy: new Ext.data.HttpProxy({ url: 'some_url', method: 'GET' }), root: 'data', fields: [ 'title', 'abstract', {name:'created_at', type:'date'}, {name: 'state', mapping: 'state.name' } ] });
-
13 Jan 2010 7:14 AM #2
If you look in JsonReader at the method "getJsonAccessor," you see there the code that is used to obtain the value. You can see that the function (closure...) it returns contains a try..catch statement which will silently absorb any errors.
This is the place where you need to try to point your debugger... looks like it won't be easy.
-
13 Jan 2010 7:24 AM #3Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
You probably need:
(this won't fail if no state is present)Code:{name: 'state', mapping: 'state', convert: function(v){return v ? v.name : null;}}
-
13 Jan 2010 8:25 AM #4
It works!!! Many thanks Condor. I've tested both options ('mapping' and 'convert') but separately, that's why it didn't work.
-
15 Apr 2010 7:40 AM #5
So what if we're mapping to an array within an object: {
name: 'address_address',
mapping: 'address.address[0].street',
convert: function(v){
return v ? v.address.address[0].street : null;
}
}
I still get this error even when I do have a convert function defined. Is there a fix for this?No longer a Newbie
-
15 Apr 2010 8:00 AM #6Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
That should be:
(are you sure it's address.address?)Code:{ name: 'address_address', mapping: 'address', convert: function(v){ return v && v.address && v.address[0] ? v.address[0].street : null; } }
-
4 Oct 2011 5:49 AM #7
Unable to use mapping in sencha touch
Unable to use mapping in sencha touch
Hi Guys.
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
-
4 Oct 2011 1:58 PM #8
There is a forum for sencha touch issues.


Reply With Quote