2013-03-26 47 views
0

我正在構建一個使用Titanium for ios的移動應用程序,而且我正在艱難地將我的手臂纏繞在傳遞變量上。我正在使用本地數據庫和遠程數據庫的組合來傳遞我的數據。在這種情況下,我想傳遞所選tableViewRow上的數據。顯示我稱之爲「categorydescription」的數據的標籤。在我的table.addEventListener中,我想將這些數據作爲新窗口的標題傳遞,並將相同的數據傳遞給遠程服務器上的php文件。這裏是我試圖使用的代碼:從JSON數據傳遞變量

var xhr = Ti.Network.createHTTPClient({ 
onload: function() { 
Ti.API.debug(this.responseText); 

var json = JSON.parse(this.responseText); 
for (i = 0; i < json.cms_client.length; i++) { 
    client = json.cms_client[i]; 
    row = Ti.UI.createTableViewRow({ 
     height:'44dp', 
     hasChild:true 
    }); 

var categorydescription = Ti.UI.createLabel({ 
     text:client.catdesc, 
     font:{fontSize:'16dp', fontWeight:'bold'}, 
    height:'auto', 
    left:'10dp', 
    color:'#000' 
    }); 

row.add(categorydescription); 
    tableData.push(row); 
} 
table.addEventListener('click',function(e) { 
    var win = Ti.UI.createWindow({url: 'clients.js', title: ??}); 
    var catdesc = ??; 
    win.catdesc = catdesc; 
    Titanium.UI.currentTab.open(win,{animated:true}); 
}); 
table.setData(tableData); 

有人會這麼好心地告訴我我需要什麼來代替?在上面的'標題'和'var catdesc'中?

回答

0

就在類別描述和標題添加到該行對象本身:

row = Ti.UI.createTableViewRow({ 
    height:'44dp', 
    hasChild:true, 
    categoryDescription : client.catdesc, //Add this 
    clientTitle : client.title // Add this 
}); 

現在讓他們在聽衆:

table.addEventListener('click',function(e) { 
    var win = Ti.UI.createWindow({url: 'clients.js', title: e.row.title}); 
    var catdesc = e.row.categoryDescription; 
    win.catdesc = catdesc; 
    Titanium.UI.currentTab.open(win,{animated:true}); 
}); 
+0

謝謝約西亞,我很欣賞,因爲我是有你的解釋很難理解如何應用我閱讀的其他帖子。 – dnevels 2013-03-26 20:02:47