Skip to content

Instantly share code, notes, and snippets.

@philsmithsonuk
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philsmithsonuk/6afe59833daeef8f3f24 to your computer and use it in GitHub Desktop.
Save philsmithsonuk/6afe59833daeef8f3f24 to your computer and use it in GitHub Desktop.
//Placed in /lib/functions.js
var getData = function(callback){
var rssFeed = Ti.Network.createHTTPClient();
rssFeed.onload = function(){
var xml = this.responseXML;
var items = xml.documentElement.getElementsByTagName("item");
var _title = "";
var tableData = [];
var row = "";
var rowLbl = "";
for(var i =0; i < items.length; i++)
{
_title = items.item(i).getElementsByTagName("title").item(0).textContent;
//create row
row = Ti.UI.createTableViewRow({
height: Ti.UI.SIZE,
guid: _guid
});
//create label for row
rowLbl = Ti.UI.createLabel({
text: _title,
textAlign: "center"
});
//add label to row
row.add(rowLbl);
//add row to tableData array
tableData.push(row);
}
//call callback function, pass data
callback(tableData);
};
rssFeed.onerror = function(e){
Ti.API.info("Error getting data from URL: "+JSON.stringify(e));
};
rssFeed.open("GET", "http://blog.foolprooflabs.com/feed/");
rssFeed.send();
};
exports.getData = getData;
var functions = require('functions');
var tblView = Ti.UI.createTableView({
backgroundColor: "red"
});
//call getdata, passing callback function
$.btn_refresh.addEventListener('click', function(){
functions.getData(function(data){
tblView.data = data;
});
});
//add table view to window
$.parentContainer.add(tblView);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment