Created
August 29, 2011 15:45
-
-
Save appcdr/1178667 to your computer and use it in GitHub Desktop.
Appcelerator: HTTPClient and JSON sample app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ti.UI.backgroundColor = '#dddddd'; | |
var url = "https://raw.github.com/appcelerator/Documentation-Examples/master/HTTPClient/data/json.txt"; | |
var win = Ti.UI.createWindow(); | |
var table = Ti.UI.createTableView(); | |
var tableData = []; | |
var json, fighters, fighter, i, row, nameLabel, nickLabel; | |
var xhr = Ti.Network.createHTTPClient({ | |
onload: function() { | |
// Ti.API.debug(this.responseText); | |
json = JSON.parse(this.responseText); | |
for (i = 0; i < json.fighters.length; i++) { | |
fighter = json.fighters[i]; | |
row = Ti.UI.createTableViewRow({ | |
height:'60dp' | |
}); | |
nameLabel = Ti.UI.createLabel({ | |
text:fighter.name, | |
font:{ | |
fontSize:'24dp', | |
fontWeight:'bold' | |
}, | |
height:'auto', | |
left:'10dp', | |
top:'5dp', | |
color:'#000', | |
touchEnabled:false | |
}); | |
nickLabel = Ti.UI.createLabel({ | |
text:'"' + fighter.nickname + '"', | |
font:{ | |
fontSize:'16dp' | |
}, | |
height:'auto', | |
left:'15dp', | |
bottom:'5dp', | |
color:'#000', | |
touchEnabled:false | |
}); | |
row.add(nameLabel); | |
row.add(nickLabel); | |
tableData.push(row); | |
} | |
table.setData(tableData); | |
}, | |
onerror: function(e) { | |
Ti.API.debug("STATUS: " + this.status); | |
Ti.API.debug("TEXT: " + this.responseText); | |
Ti.API.debug("ERROR: " + e.error); | |
alert('There was an error retrieving the remote data. Try again.'); | |
}, | |
timeout:5000 | |
}); | |
xhr.open("GET", url); | |
xhr.send(); | |
win.add(table); | |
win.open(); |
hello, how to see on click row the nickLabel on new window
@tona: do you want to capture the label from the row and display in the new window?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, nice example