I make a call to a server that gives me back a JSON. What I want to do is to populate a ListView with a special template (for ie. : the name on a first line and the town on a second line at the bottom). Right now there is no template in my code, I tried but I failed.
Here is the JSON :
[{"id":1,"name":"james","town":"london"}, {"id":2,"name":"paul","town":"new-york"}, {"id":3,"name":"mary","town":"sydney"}]
Here my JS :
var client = Ti.Network.createHTTPClient({ onload : function(e) { var people = JSON.parse(this.responseText); var items = []; _.each(people, function(person){ items.push({ properties : {title: person.name } }); }); $.elementsList.sections[0].setItems(items); }, onerror : function(e) { Ti.API.debug(e.error); alert('error '); }, timeout : 5000 }); client.open("GET", url); client.send(); $.index.open();
Here is my XML :
<Alloy> <Window class="container"> <View id="topBar" /> <View id="topMenu"> <Button id="reloadButton">Reload</Button> </View> <ListView id="elementsList"> <ListSection name="elements" /> </ListView> </Window> </Alloy>