2013-02-07 21 views
0

我正在用Titanium構建應用程序,我試圖從JSON對象生成汽車列表,但我似乎沒有得到任何結果。當我在循環內記錄變量時,我得到'未定義'。我在這裏做錯了什麼?從JSON對象中添加Titanium中的表格行

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(); 

任何幫助非常感謝,感謝您的時間。

回答

2

我在循環中看不到您的調試語句。但是,您正試圖在您的行標題中引用cars.title,並且這將是未定義的。 cars [i] .title將作爲循環中當前對象的標題字段的引用。