I’m building an app with Titanium and I’m trying to generate a list of cars from a JSON object but I don’t seem to be getting any results. When I log the variable inside the loop I’m getting ‘undefined’. Am I doing something wrong here?
var cars = [
{title: 'VW Golf', pricePerHour: '6€'},
{title: 'Peugeot 206', pricePerHour: '5€'},
{title: 'Renault Clio', pricePerHour: '6,50€'}
];
var tableData = [];
var tableView = Titanium.UI.createTableView();
for (var i = 0; i < cars.length; i++) {
var tR = Ti.UI.createTableViewRow({
title: cars.title,
height: 100
});
tableData.push(tR);
}
tableView.setData(tableData);
main.add(tableView);
main.open();
Any help is much appreciated, thank you for your time.
I don’t see your debug statement inside the loop. However you are attempting to reference cars.title in your row title, and this would be undefined. cars[i].title will be the reference to the title field of the current object in the loop.