如何将外部 JSON 数据加载到轮播中
伙计们。我已经开始使用 Sencha Touch,但在第一次尝试创建读取 JSON 文件然后将内容放入轮播单元(有 6 个)的简单应用程序时遇到了困难。
这是到目前为止的代码:
Ext.setup({
icon: 'icon.png',
glossOnIcon: false,
phoneStartupScreen: 'phone_startup.png',
onReady: function() {
var arena_zapad = new Ext.Component({
title: 'Arena Zapad',
scroll: 'vertical',
tpl: [
'<tpl for=".">',
'<div class="movie">',
'<div class="title"><h2>{title}</h2></div>',
'<div class="days">{days}</div>',
'</div>',
'</tpl>'
]
});
var refresh = function() {
Ext.util.JSONP.request({
url: 'arena_zapad.json',
callbackKey: 'callback',
callback: function(data) {
arena_zapad.update(data)
}
})
}
new Ext.TabPanel({
fullscreen: true,
tabBar: {
dock: 'bottom',
layout: {pack: 'center'}
},
animation: 'slide',
items: [{
title: 'Movie Theaters',
iconCls: 'monitor2',
xtype: 'carousel',
items: [
{ html: "Arena Mladost",
cls: 'card card2'
// I want the json data here instead of html text
},{
html: 'Arena West',
cls: 'card card2'
},{
html: 'Арена The Mall',
cls: 'card card3'
},{
html: 'Cineplex',
cls: 'card card3'
},{
html: 'Cinema City',
cls: 'card card3'
},{
html: 'M-TEL IMAX',
cls: 'card card3'
}]
}, {
title: 'Movies',
html: 'Movies',
iconCls: 'video_black2',
cls: 'card card1'
}, {
title: 'Premier',
html: 'Premier',
iconCls: 'photo3',
cls: 'card card3'
}, {
title: 'Favourites',
html: 'Favourites',
iconCls: 'favorites',
cls: 'card card1'
}, {
title: 'About',
html: 'About',
iconCls: 'info2',
cls: 'card card5'
}]
});
}
});
这是 json 文件:
{
"movies": [
{
"days": "Digital: 12:15, 14:15, 16:15, 18:15, 20:15, 22:15 35MM: 11:15, 13:15, 15:15, 17:15, 19:15, 21:15, 23:15",
"title": "TILT"
},
{
"days": "9 февруари (сряда), 13:10, 15:30, 17:50, 19:00, 20:10, 21:20, 22:30",
"title": "Бурлеска"
},
{
"days": "9 февруари (сряда), 12:00, 16:15",
"title": "Запознай се с малките"
}
]
}
所以基本上我想加载该文件,解析它并将其放入第一个轮播“单元格”中(然后填充其他“单元格”)。我已经查看了文档,但我不知道如何做到这一点。任何帮助将不胜感激。
提前致谢。
guys. I've started playing with Sencha Touch and I've hit the wall in my first attempt to create simple app that read JSON file and then put the content into carousel cell (there are 6).
Here is the code so far:
Ext.setup({
icon: 'icon.png',
glossOnIcon: false,
phoneStartupScreen: 'phone_startup.png',
onReady: function() {
var arena_zapad = new Ext.Component({
title: 'Arena Zapad',
scroll: 'vertical',
tpl: [
'<tpl for=".">',
'<div class="movie">',
'<div class="title"><h2>{title}</h2></div>',
'<div class="days">{days}</div>',
'</div>',
'</tpl>'
]
});
var refresh = function() {
Ext.util.JSONP.request({
url: 'arena_zapad.json',
callbackKey: 'callback',
callback: function(data) {
arena_zapad.update(data)
}
})
}
new Ext.TabPanel({
fullscreen: true,
tabBar: {
dock: 'bottom',
layout: {pack: 'center'}
},
animation: 'slide',
items: [{
title: 'Movie Theaters',
iconCls: 'monitor2',
xtype: 'carousel',
items: [
{ html: "Arena Mladost",
cls: 'card card2'
// I want the json data here instead of html text
},{
html: 'Arena West',
cls: 'card card2'
},{
html: 'Арена The Mall',
cls: 'card card3'
},{
html: 'Cineplex',
cls: 'card card3'
},{
html: 'Cinema City',
cls: 'card card3'
},{
html: 'M-TEL IMAX',
cls: 'card card3'
}]
}, {
title: 'Movies',
html: 'Movies',
iconCls: 'video_black2',
cls: 'card card1'
}, {
title: 'Premier',
html: 'Premier',
iconCls: 'photo3',
cls: 'card card3'
}, {
title: 'Favourites',
html: 'Favourites',
iconCls: 'favorites',
cls: 'card card1'
}, {
title: 'About',
html: 'About',
iconCls: 'info2',
cls: 'card card5'
}]
});
}
});
And here is the json file:
{
"movies": [
{
"days": "Digital: 12:15, 14:15, 16:15, 18:15, 20:15, 22:15 35MM: 11:15, 13:15, 15:15, 17:15, 19:15, 21:15, 23:15",
"title": "TILT"
},
{
"days": "9 февруари (сряда), 13:10, 15:30, 17:50, 19:00, 20:10, 21:20, 22:30",
"title": "Бурлеска"
},
{
"days": "9 февруари (сряда), 12:00, 16:15",
"title": "Запознай се с малките"
}
]
}
So basically I want to load that file, parse it and put it in the first carousel "cell" (and later to populate the other "cells"). I've looked at the documentation but I cannot figure it how to do it. Any help will be appreciated.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您位于同一域中,则无需使用 JSONP 进行加载。只需使用 Ext.Ajax.request 即可。有一个从xml加载轮播内容的例子,思路是一样的。
There's no need to use JSONP to load if you're on the same domain. Just use Ext.Ajax.request. There is an example of loading carousel content from xml, the idea is the same.
你看过这个例子吗? http://www.netmagazine.com/tutorials/build-ipad-app -sencha-touch
构建应用程序的非常深入的教程,从另一个来源(我认为是 Youtube,不记得了)提取数据并填充大约 48 个具有可点击覆盖层的缩略图 - 非常酷。
硅
Have you looked at this example? http://www.netmagazine.com/tutorials/build-ipad-app-sencha-touch
Very in-depth tutorial at building an app the pulls data from another source (I think it's Youtube, can't remember) and populates about 48 thumbnails that have clickable overlays - very cool.
Si