Created
February 9, 2015 19:21
-
-
Save devmoreno/d683b4d8ec5b30afb0f7 to your computer and use it in GitHub Desktop.
Titanium
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.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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment