PDA

View Full Version : Newbie question: display local json data in a panel



gigignu
31 Jan 2011, 9:59 AM
Hi to all,
i'm a newbie to sencha touch and very noob to javascript language.

I 'm trying to write an app that display in a panel, (instead of html: property) an html content included in a file (for example, turismo.json)

I am on this point:
my model and store are:


Ext.regModel('Content', {
fields: [
{name: 'content_id', type: 'string'},
{name: 'content_title', type: 'string'},
{name: 'content_html', type: 'string'},
{name: 'content_image', type: 'string'}
]
});

var contentTurismo = new Ext.data.Store({
model: 'Content',
proxy: {
type: 'localstorage',
id : 'turismo-localproxy',
url : 'data/turismo.json',
reader: {
type: 'json',
root: 'contents'
}
},
autoLoad: true
});

var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<div id="cont">',
'<p>{content_title}</p>',
'<img src="img/{content_image}" />',
'<p>{content_html}',
'</p>',
'</div>',
'</tpl>'
);
and my local file is turismo.json:


{
"contents": [
{"content_id": "1", "content_title": "Turismo", "content_html": "Prova HTML", "content_image": "img/turismo.jpg"},
{"content_id": "2", "content_title": "Pagina 2", "content_html": "Prova Json Pagina 2", "content_image": "caratteri.jpg"},
{"content_id": "3", "content_title": "Pagina 3", "content_html": "Prova Json Pagina 3", "content_image": "cosavisitare.jpg"},

]
}
and now... how i can display only the first item of my local turismo.json content in my panel ?

thanks for help .. and sorry for my bad english