简体   繁体   English

从JSON数据传递变量

[英]Passing Variable from JSON data

I am building a mobile app using Titanium for ios and I am having a tough time getting my arms wrapped around passing variables. 我正在使用Titanium for ios构建一个移动应用程序,并且我很难把自己的胳膊缠在传递变量上。 I am using a combination of local database and remote database to deliver my data. 我正在使用本地数据库和远程数据库的组合来传递数据。 In this case I want to pass the data on the tableViewRow selected. 在这种情况下,我想将数据传递到所选的tableViewRow上。 The label that displays the data I call "categorydescription". 显示数据的标签称为“类别描述”。 In my table.addEventListener, I want to pass that data as the title for the new window and I will pass that same data to my php file on the remote server. 在我的table.addEventListener中,我想将该数据作为新窗口的标题传递,并将相同的数据传递给远程服务器上的php文件。 Here is the code I am trying to use: 这是我尝试使用的代码:

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

Would someone be so kind to tell me what I need to put in place of the ?? 有人会这样告诉我我需要代替??吗? in the 'title' and 'var catdesc' above? 在上面的“标题”和“ var catdesc”中?

Just add the category description and title to the row object itself: 只需将类别描述和标题添加到行对象本身即可:

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

Now get them in the listener: 现在将它们放入侦听器中:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM