Skip to content

Instantly share code, notes, and snippets.

@devmoreno
Created February 9, 2015 19:21
Show Gist options
  • Select an option

  • Save devmoreno/d683b4d8ec5b30afb0f7 to your computer and use it in GitHub Desktop.

Select an option

Save devmoreno/d683b4d8ec5b30afb0f7 to your computer and use it in GitHub Desktop.

Revisions

  1. devmoreno created this gist Feb 9, 2015.
    48 changes: 48 additions & 0 deletions gistfile1.js
    Original 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
    }