Create a gist now

Instantly share code, notes, and snippets.

//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