PDA

View Full Version : complex JsonStore



luca.santaniello
3 Dec 2009, 12:15 AM
HI,

I have this JsonStore and this Template



store = new Ext.data.JsonStore({
fields: [
{name: 'nome', type: 'string'}
]
});

templateRow = new Ext.Template(
'<p><b>Mappa:</b> {nome}<br>'
);


I use 2 Component for loading my grid...

My json string is :

bbox->object
corrente->boolean
layers->array object
name->string

For example:


[{"bbox":{"XMax":19.0,"XMin":10.5,"YMax":42.7,"YMin":38.7,"srs":""},"corrente":false,"layers":[{"baseLayer":true,"bbox":null,"description":"","label":"Comuni","name":"TestPG:carto_limiti_comunali","server":"http://10.0.0.190:8080/geoserver/wms?","srs":"","style":"","visible":true},{"baseLayer":false,"bbox":null,"description":"","label":"Aereoporti","name":"TestPG:carto_aereoporti","server":"http://10.0.0.190:8080/geoserver/wms?","srs":"","style":"","visible":true}],"nome":"map"},{"bbox":{"XMax":19.086215820312,"XMin":10.593784179686,"YMax":43.148046875,"YMin":38.401953125,"srs":""},"corrente":true,"layers":[{"baseLayer":true,"bbox":null,"description":"","label":"Comuni","name":"TestPG:carto_limiti_comunali","server":"http://10.0.0.190:8080/geoserver/wms?","srs":"","style":"","visible":true},{"baseLayer":false,"bbox":null,"description":"","label":"Aereoporti","name":"TestPG:carto_aereoporti","server":"http://10.0.0.190:8080/geoserver/wms?","srs":"","style":"","visible":true}],"nome":"LUCA"}]


How can I add to my JsonStore and my Template attributes of object bbox?

I try
[CODE]
store = new Ext.data.JsonStore({
fields: [
{name: 'nome', type: 'string'},
{name: 'bbox', type: 'object'},
]
});
[CODE]

but don't run

Help me please

Luca

luca.santaniello
23 Dec 2009, 12:49 AM
Can help me please? :((

My json string is:

[{"bbox":{"XMax":19.0,"XMin":10.5,"YMax":42.7},"nome":'AAA']

How can create my store?

fields: [
{name: 'nome', type: 'string'},
{name: 'bbox', type: 'object'},
]

and using my fields into template?


var templateRow = new Ext.Template(
'<p>',
' <b>Mappa:</b> {nome}<br>',
' <b>XMAX:</b> {bbox.XMax}<br>',
'</p>'
);
Thanks

Condor
23 Dec 2009, 4:39 AM
fields: [
{name: 'nome', type: 'string'},
{name: 'bbox'}
]
with:

var templateRow = new Ext.Template(
'<p>',
' <b>Mappa:</b> {nome}<br>',
' <b>XMAX:</b> {values.bbox.XMax}<br>',
'</p>'
);

luca.santaniello
23 Dec 2009, 5:26 AM
fields: [
{name: 'nome', type: 'string'},
{name: 'bbox'}
]with:

var templateRow = new Ext.Template(
'<p>',
' <b>Mappa:</b> {nome}<br>',
' <b>XMAX:</b> {values.bbox.XMax}<br>',
'</p>'
);

This code not working properly, it print:

Mappa: myName
XMAX: {values.bbox.XMax}

Help me

Condor
23 Dec 2009, 5:41 AM
You need an Ext.XTemplate to support '.' in names.

luca.santaniello
23 Dec 2009, 5:47 AM
You need an Ext.XTemplate to support '.' in names.

It run, thank you very much

luca.santaniello
23 Dec 2009, 6:41 AM
If I have array? How can print all items?

Example

{name: 'aaa', items: [{name: 'qqq', num: 1},{name: 'ggg', num: 2},{name: 'hhh', num: 3}]}

I want print
name: 'qqq', num: 1
name: 'ggg', num: 2
name: 'hhh', num: 3

Is it possible?

Condor
23 Dec 2009, 6:48 AM
Read the XTemplate docs (you need to use a <tpl for="..."></tpl>).

Mike Robinson
23 Dec 2009, 8:46 AM
And sometimes, for whatever it may be worth, you just have to build a string the old-fashioned way. I've had trouble with looping in XTemplates (when I wanted to "get fancy" :>), but it was a simple thing to build my own loop, construct a string (using templates for convenience in the loop), and then do what "overwrite" does. I guess that I could have "figured it out," but that would have caused me to miss deadline.