hey to all I've been reading the appcelerator development cookbook...im very curious on chapter 2/ recipe 3..i have a tableview..which is suppose to put remote data xml....but I'm confused about the data and xml....and i want to know why the tableview is empty..with no recipes showing???
var win = Ti.UI.currentWindow; //declare the http client object var xhr = Titanium.Network.createHTTPClient(); var data = []; //empty data array var tblRecipes = Titanium.UI.createTableView({ height: 366, width: 320, top: 0, left: 0, rowHeight: 70 }); win.add(tblRecipes); //this method will process the remote data xhr.onload = function() { var xml = this.responseXML; //get the item nodelist from our response xml object var items = xml.documentElement.getElementsByTagName("item"); //loop each item in the xml for (var i = 0; i < items.length; i++) { //create a table row var row = Titanium.UI.createTableViewRow({ hasChild: true, className: 'recipe-row' }); //title label var titleLabel = Titanium.UI.createLabel({ text: items.item(i).getElementsByTagName("title").item(0).text, font: {fontSize: 14, fontWeight: 'bold'}, left: 70, top: 5, height: 20, width: 210 }); row.add(titleLabel); //description label var descriptionLabel = Titanium.UI.createLabel({ text: items.item(i).getElementsByTagName("description").item(0).text, font: {fontSize: 10, fontWeight: 'normal'}, left: 70, top: 25, height: 40, width: 200 }); if(descriptionLabel.text == '') { descriptionLabel.text = 'No description is available.'; } row.add(descriptionLabel); //add our little icon to the left of the row var iconImage = Titanium.UI.createImageView({ image: 'images/foodicon.jpg', width: 50, height: 50, left: 10, top: 10 }); row.add(iconImage); //add the table row to our data[] object data.push(row); } //finally, set the data property of the tableView to our data[] object tblRecipes.data = data; };
1 Answer
You don't show calls to xhr.open() and xhr.send(). Maybe you didn't grab those lines when you copied and pasted.
But if you don't have those calls, you're not making a network request, and the onload() function won't get called.
Your Answer
Think you can help? Login to answer this question!