Created
February 9, 2015 19:21
-
-
Save devmoreno/d683b4d8ec5b30afb0f7 to your computer and use it in GitHub Desktop.
Revisions
-
devmoreno created this gist
Feb 9, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ exports.model = function(){ //Declare our dictionary to return to the table view var model; //Connection Example /* * First we create our url and our response variable and then create our client function */ var url = "http://takeoutapi.azurewebsites.net/api/menu/", response; var checkConn = Ti.Network.createHTTPClient({ //On Sucess onload : function() { Ti.API.info(this.responseText); response = this.responseText; }, //On Error onerror: function(){ Ti.API.info("error"); }, //Wait 5 seconds timeout: 5000 }); //Open our connection and send them. Our results will be store on @response variable checkConn.open("GET", url); checkConn.send(); //Create our data array for our table view. We have to iterate through our response to create a new array with the right properties var data = []; for (var iterate in response) { var newObj = { title: response.Name }; data.push(newObj); console.log("this is iterating through response "+iterate); } console.log("Data: "+data); model = data; return model }