PDA

View Full Version : JSON + JsonStore mapping field doesn't work



gomes.lucas
10 Sep 2009, 5:35 AM
Hi folks!

I'm trying to recover some data from a JSON object with a JsonStore, and in a particulary field I'm trying to mapping some information, but isn't working just in this field. I'm new in Ext, I couldn't find some examples about it so if you guys help me I would apreciate it!
Let me show my code:

JSON:


[{
"id":282,
"descricao":"logotipo",
"nome":"LOGO",
"recursoReferencia":"rec",
"valorRecurso":{
"arquivo":"/usr/storage\\0000002433\\20090529124411.jpg",
"descricao":"Image Logotipo",
"id":283,
"nome":"Logotipo"
}
}]


and how I'm getting all this stuff on Ext:



var storeParametrosExecucao = new Ext.data.JsonStore({
url: 'urlurl'
,fields: [
{name: 'id'}
,{name: 'nome', type: 'string', sortType: Ext.data.SortTypes.asUCString}
,{name: 'descricao', type: 'string', sortType: Ext.data.SortTypes.asUCString}
,{name: 'valorRecurso', type:'string', mapping: 'valorRecurso.id'}
]
,sortInfo: {
field: 'nome'
}
,autoLoad: false
});


Thx in advance

Condor
10 Sep 2009, 5:44 AM
There is nothing wrong with the example you posted.

What exactly is the problem you are having?

gomes.lucas
10 Sep 2009, 5:49 AM
Condor, when I take this "valorRecurso.id" out of my JsonStore, my grid is rendered with no problem. With this expression it isnt, and I don't know why....

Condor
10 Sep 2009, 5:52 AM
Are you sure that every record has a valorRecurso object?

Otherwise you need to use:

{name: 'valorRecurso', type:'string', mapping: 'valorRecurso', convert: function(v){
return v ? v.id : '';
}}

gomes.lucas
10 Sep 2009, 6:02 AM
Oh! It's true... sometimes the attribute valor will be null, sometimes valorRecurso... that's why it can't render my Grid, hehe.

Thx Condor!