indieangler
6 Jul 2010, 2:27 PM
I'm looking for help with the following code that's just a simple JSONP request to get data from a different server and display it via a simple template. I'm very new to Sencha and ExtJS but I'm doing my best. I've tried messing with this code all afternoon and I can't seem to figure out what's going wrong even though it seems like it should be working fine. If this ends up being a double post, I apologize, admin please delete the original as this one makes much more sense and is more helpful than my original request.
The index.js code is as follows:
Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady: function() {
var blogs = new Ext.Component({
title: 'Blog Data',
cls: 'timeline',
scroll: 'vertical',
tpl: [
'<tpl for=".">',
'<p><h2>{title}</h2>',
'posted on {date}<br />',
'{post}<br />{link}</p>',
'</tpl>'
]
});
var panel = new Ext.TabPanel({
fullscreen: true,
animation: 'slide',
items: [blogs]
});
var refresh = function() {
Ext.util.JSONP.request({
url: 'http://www.calculatewhat.com/data.json',
callbackKey: 'callback',
callback: function(data) {
data = data.results;
blogs.update(data.results);
}
});
};
var tabBar = panel.getTabBar();
tabBar.addDocked({
xtype: 'button',
ui: 'mask',
iconCls: 'refresh',
dock: 'right',
stretch: false,
align: 'center',
handler: refresh
});
}
});
And the external data.json file I'm trying to play with looks like this:
[{
"title":"Title 1",
"post":"Post Text 1",
"date":"Date 1",
"link": "URL 1"
}, {
"title":"Title 2",
"post":"Post Text 2",
"date":"Date 2",
"link": "URL 2"
}]
I'm not sure if the problem is in the JSON data file or in the way I'm calling it and the code on index.js. I'm hoping this is pretty basic and someone can push me in the right direction to getting this solved because it's starting to drive me crazy. Thanks!
The index.js code is as follows:
Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,
onReady: function() {
var blogs = new Ext.Component({
title: 'Blog Data',
cls: 'timeline',
scroll: 'vertical',
tpl: [
'<tpl for=".">',
'<p><h2>{title}</h2>',
'posted on {date}<br />',
'{post}<br />{link}</p>',
'</tpl>'
]
});
var panel = new Ext.TabPanel({
fullscreen: true,
animation: 'slide',
items: [blogs]
});
var refresh = function() {
Ext.util.JSONP.request({
url: 'http://www.calculatewhat.com/data.json',
callbackKey: 'callback',
callback: function(data) {
data = data.results;
blogs.update(data.results);
}
});
};
var tabBar = panel.getTabBar();
tabBar.addDocked({
xtype: 'button',
ui: 'mask',
iconCls: 'refresh',
dock: 'right',
stretch: false,
align: 'center',
handler: refresh
});
}
});
And the external data.json file I'm trying to play with looks like this:
[{
"title":"Title 1",
"post":"Post Text 1",
"date":"Date 1",
"link": "URL 1"
}, {
"title":"Title 2",
"post":"Post Text 2",
"date":"Date 2",
"link": "URL 2"
}]
I'm not sure if the problem is in the JSON data file or in the way I'm calling it and the code on index.js. I'm hoping this is pretty basic and someone can push me in the right direction to getting this solved because it's starting to drive me crazy. Thanks!