Created
March 17, 2015 13:32
-
-
Save aaronksaunders/9ef5af751fbfe8825ee3 to your computer and use it in GitHub Desktop.
From Simple Appcelerator Titanium Alloy App Videos - https://www.youtube.com/watch?v=Sz_V5HAqroU
This file contains hidden or 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
| // | |
| var peopleService = require('peopleService'); | |
| /** | |
| * called when user clicks on table view. The _event will provide | |
| * the index of the item clicked in the table | |
| * | |
| * @param {Object} _event | |
| */ | |
| function clickedOnTableView(_event) { | |
| // display to console log the _event object for debugging | |
| Ti.API.info(JSON.stringify(_event,null,2)); | |
| // get data using index provided, show alert | |
| alert("clicked on " + sampleTableData[_event.index].title); | |
| } | |
| // Set the sample data, the tableView by default will render what the | |
| // title property is set to | |
| var sampleTableData = [ | |
| {"title":"Aaron", }, | |
| {"title":"Andrea"}, | |
| {"title":"Bryce"}, | |
| {"title":"Reina"} | |
| ]; | |
| // set data | |
| $.myTableView.data = sampleTableData; | |
| // open the view | |
| $.index.open(); | |
| peopleService.getPeople(function(_response){ | |
| if (_response.success) { | |
| } else { | |
| Ti.API.info('ERROR - ' + _response.error); | |
| } | |
| }); |
This file contains hidden or 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
| ".container": { | |
| backgroundColor:"white" | |
| } | |
| "Label": { | |
| width: Ti.UI.SIZE, | |
| height: Ti.UI.SIZE, | |
| color: "#000" | |
| } | |
| "#label": { | |
| font: { | |
| fontSize: 12 | |
| } | |
| } |
This file contains hidden or 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
| <Alloy> | |
| <!-- on IOS we add the NavigationWindow to wrap UI, | |
| this will place the tableView properly in the page --> | |
| <NavigationWindow> | |
| <Window class="container"> | |
| <!-- listen for click and call the function specified --> | |
| <TableView id="myTableView" onClick="clickedOnTableView"></TableView> | |
| </Window> | |
| </NavigationWindow> | |
| </Alloy> |
This file contains hidden or 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
| exports.getPeople = function(_callback) { | |
| // https://randomuser.me/ for information on API | |
| //http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.Network.HTTPClient | |
| // specify the numbers of user you want returned | |
| var url = 'http://api.randomuser.me/?results=20'; | |
| var client = Ti.Network.createHTTPClient({ | |
| // function called when the response data is available | |
| onload : function(e) { | |
| Ti.API.info("Received text: " + this.responseText); | |
| // API will convert to JSON for you!! | |
| _callback({ | |
| success : true, | |
| data : this.responseJSON | |
| }); | |
| }, | |
| // function called when an error occurs, including a timeout | |
| onerror : function(e) { | |
| Ti.API.debug(e.error); | |
| _callback({ | |
| success : false, | |
| error : e | |
| }); | |
| }, | |
| timeout : 5000 // in milliseconds | |
| }); | |
| // Prepare the connection. | |
| client.open("GET", url); | |
| // Send the request. | |
| client.send(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment