Titanium mobile 单击钛合金中的行显示城市详细信息

Titanium mobile 单击钛合金中的行显示城市详细信息,titanium-mobile,appcelerator,titanium-android,Titanium Mobile,Appcelerator,Titanium Android,您好,我是编程初学者,我正在尝试使用HTTPClient构建一个简单的钛应用程序。这段代码显示了城市的完整列表,我希望在单击每个城市时,它会显示在另一个窗口中,单击城市的照片 此代码显示城市的完整列表: Ti.UI.backgroundColor = '#000'; var url = "http://10.0.3.2:8000/cities/.json"; var win = Ti.UI.createWindow(); var table = Ti.UI.createT

您好,我是编程初学者,我正在尝试使用HTTPClient构建一个简单的钛应用程序。这段代码显示了城市的完整列表,我希望在单击每个城市时,它会显示在另一个窗口中,单击城市的照片

此代码显示城市的完整列表:

Ti.UI.backgroundColor = '#000';
    var url = "http://10.0.3.2:8000/cities/.json";
    var win = Ti.UI.createWindow();
    var table = Ti.UI.createTableView();
    var tableData = [];
    var json, i, row, nameLabel, nickLabel;

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

        json = JSON.parse(this.responseText);
        for (i = 0; i < json.length; i++) {

            row = Ti.UI.createTableViewRow({
                height:'60dp'
            });
            nameLabel = Ti.UI.createLabel({
                text:json[i].city,
                font:{
                    fontSize:'24dp',
                fontWeight:'bold'
            },
            height:'auto',
            left:'10dp',
            top:'5dp',
            color:'#000',
            touchEnabled:false
            });
            nickLabel = Ti.UI.createLabel({
            text:'"' + json[i].city + '"',
            font:{
                fontSize:'16dp'
            },
            height:'auto',
            left:'15dp',
            bottom:'5dp',
            color:'#000',
            touchEnabled:false
            });

            row.add(nameLabel);
            row.add(nickLabel);
            tableData.push(row);



 }

    table.setData(tableData);
    },
    onerror: function(e) {
    Ti.API.debug("STATUS: " + this.status);
    Ti.API.debug("TEXT:   " + this.responseText);
    Ti.API.debug("ERROR:  " + e.error);
    alert('Per momentin nuka ka te dhena! ju lutem provojeni perseri me vone!!!');
    },
    timeout:5000
});

xhr.open("GET", url);
xhr.send();

win.add(table);
win.open();
b显示单击城市详细信息的API:


我希望在你的帮助下

以下是一段视频,展示了完整的编码过程:

添加事件侦听器

table.addEventListener('click',clickedOnTableView);

然后将事件侦听器添加到nameLabel以打开一个窗口。您可以将参数作为image或cityID传递,以显示您喜欢的任何内容。
[{"id": 2, "city": "Lezhe", "photo_city": "null"}]
/**
 * called when user clicks on table view. The _event will provide
 * the index of the item clicked in the table
 * 
 * @param {Object} _event
 */
function clickedOnTableView(_event) {
    // display to console log the _event object for debugging
    Ti.API.info(JSON.stringify(_event,null,2));

    // get data using index provided, show alert
    // show all data changes now
    alert("clicked on " + tableData[_event.index].city + " " +
     tableData[_event.index].id);
}
table.addEventListener('click',clickedOnTableView);