[英]Passing Variable from JSON data
我正在使用Titanium for ios構建一個移動應用程序,並且我很難把自己的胳膊纏在傳遞變量上。 我正在使用本地數據庫和遠程數據庫的組合來傳遞數據。 在這種情況下,我想將數據傳遞到所選的tableViewRow上。 顯示數據的標簽稱為“類別描述”。 在我的table.addEventListener中,我想將該數據作為新窗口的標題傳遞,並將相同的數據傳遞給遠程服務器上的php文件。 這是我嘗試使用的代碼:
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”中?
只需將類別描述和標題添加到行對象本身即可:
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});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.