钛移动:在按钮单击问题上从表格视图获取行值

发布于 2025-01-06 20:22:30 字数 4113 浏览 0 评论 0原文

你好朋友,

我正在 Titanium Development 中使用 Google Place API 开发一个应用程序,并成功获取数据并在表格视图中显示并在每行中添加按钮,但我的问题是我想在每行中单击按钮时获取名称和地址 所以请给我想法或任何链接来解决我的问题。

请看一下我的屏幕截图,以便在 btnclick 上我想获取姓名和地址。

提前致谢。

var categoryName;   
var addressLabel;
var row;

var tableData=[];

PlacesListCells = function createRow() 
{ 
    //var tableData=[];

    var loader = Titanium.Network.createHTTPClient();

    var url = "https://maps.googleapis.com/maps/api/place/search/json?";    
    url = url + "location=" + lat + ',' + lon;
    url = url + "&radius=" + radius;
    url = url + "&name=" + name;
    url = url + "&sensor=" + sensor;
    url = url + "&key=" + key;

    Ti.API.info(url);
    // Sets the HTTP request method, and the URL to get data from
    loader.open("GET",url);
    // Create our HTTP Client and name it "loader"
    // Runs the function when the data is ready for us to process
    loader.onload = function() 
    {
        var obj = JSON.parse(this.responseText);
        Ti.API.log(obj);    
        var results = obj.results;
        Ti.API.log(results);


        for (var i = 0; i < results.length; i++)
        {
            categoryName = obj.results[i].name; 
            reference = obj.results[i].reference;
            Ti.API.log('Refernce:'+reference);

            // Create a row and set its height to auto
            row = Titanium.UI.createTableViewRow({height:'78'});

            var placeImage =  Titanium.UI.createImageView
            ({
                image:'../iphone/appicon.png',
                width:70,
                height:50,
                top:12,
                left:5
            });

            // Create the label to hold the tweet message
            var nameLabel = Titanium.UI.createLabel({
                //text:name,
                left:80,
                top:5,
                height:'auto',
                width:185,
                textAlign:'left',
                font:{fontSize:12}
            });

            // Create the label to hold the tweet message
            addressLabel = Titanium.UI.createLabel({
                left:80,
                top:25,
                height:'auto',
                width:185,
                textAlign:'left',
                font:{fontSize:14}
            });

            var arrowImage = Ti.UI.createImageView
            ({
                image:'../iphone/appicon.png',
                width:20,
                height:20,
                left:280,
                top:30
            });

            var favoriteButton = Ti.UI.createButton
            ({
                title:'btn',
                //font:{fontFamily:'Helvetica Neue',fontSize:15},
                top:20,
                left:255,
                height:30,
                width:50,
                url:'../Images/favorite.png'
                //image:'../Images/favorite.png'
            });

            nameLabel.text = categoryName;

            getDetailsData(addressLabel,row,i);

            row.add(placeImage);
            row.add(nameLabel);
            row.add(addressLabel);
            row.add(favoriteButton);
            //row.add(arrowImage);

            tableData[i] = row;

            //set page title for each row
            row.pageTitle = nameLabel.text;

            favoriteButton.row = i;
            favoriteButton.addEventListener('click', function(e)
            {
                Ti.API.log('favoriteButton clicked on row ' + e.source.row +' at ' + new Date().getSeconds());
                alert('favoriteButton clicked on row ' + e.source.row);

                var index = e.source.row;
                var name = tableData[index];
                alert('name'+name);

            });
        }       
        tableView.setData(tableData);       
    };
    //-- Network error
    loader.onerror = function(e)
    {
        Ti.API.info('Network error: ' + JSON.stringify(e));
    };

    // Send the HTTP request
    loader.send();

    return  tableData;
};

在此处输入图像描述

Hello friends,

I am developing an app using Google Place API in Titanium Development and successfully got data and display in tableview and add button in each row but my issue is that I want to get name and address on button click in each row so please give me idea or any link to solve my issue.

Please take a look in my screenshot so on btnclick I want to get name and address.

Thanks in advance.

var categoryName;   
var addressLabel;
var row;

var tableData=[];

PlacesListCells = function createRow() 
{ 
    //var tableData=[];

    var loader = Titanium.Network.createHTTPClient();

    var url = "https://maps.googleapis.com/maps/api/place/search/json?";    
    url = url + "location=" + lat + ',' + lon;
    url = url + "&radius=" + radius;
    url = url + "&name=" + name;
    url = url + "&sensor=" + sensor;
    url = url + "&key=" + key;

    Ti.API.info(url);
    // Sets the HTTP request method, and the URL to get data from
    loader.open("GET",url);
    // Create our HTTP Client and name it "loader"
    // Runs the function when the data is ready for us to process
    loader.onload = function() 
    {
        var obj = JSON.parse(this.responseText);
        Ti.API.log(obj);    
        var results = obj.results;
        Ti.API.log(results);


        for (var i = 0; i < results.length; i++)
        {
            categoryName = obj.results[i].name; 
            reference = obj.results[i].reference;
            Ti.API.log('Refernce:'+reference);

            // Create a row and set its height to auto
            row = Titanium.UI.createTableViewRow({height:'78'});

            var placeImage =  Titanium.UI.createImageView
            ({
                image:'../iphone/appicon.png',
                width:70,
                height:50,
                top:12,
                left:5
            });

            // Create the label to hold the tweet message
            var nameLabel = Titanium.UI.createLabel({
                //text:name,
                left:80,
                top:5,
                height:'auto',
                width:185,
                textAlign:'left',
                font:{fontSize:12}
            });

            // Create the label to hold the tweet message
            addressLabel = Titanium.UI.createLabel({
                left:80,
                top:25,
                height:'auto',
                width:185,
                textAlign:'left',
                font:{fontSize:14}
            });

            var arrowImage = Ti.UI.createImageView
            ({
                image:'../iphone/appicon.png',
                width:20,
                height:20,
                left:280,
                top:30
            });

            var favoriteButton = Ti.UI.createButton
            ({
                title:'btn',
                //font:{fontFamily:'Helvetica Neue',fontSize:15},
                top:20,
                left:255,
                height:30,
                width:50,
                url:'../Images/favorite.png'
                //image:'../Images/favorite.png'
            });

            nameLabel.text = categoryName;

            getDetailsData(addressLabel,row,i);

            row.add(placeImage);
            row.add(nameLabel);
            row.add(addressLabel);
            row.add(favoriteButton);
            //row.add(arrowImage);

            tableData[i] = row;

            //set page title for each row
            row.pageTitle = nameLabel.text;

            favoriteButton.row = i;
            favoriteButton.addEventListener('click', function(e)
            {
                Ti.API.log('favoriteButton clicked on row ' + e.source.row +' at ' + new Date().getSeconds());
                alert('favoriteButton clicked on row ' + e.source.row);

                var index = e.source.row;
                var name = tableData[index];
                alert('name'+name);

            });
        }       
        tableView.setData(tableData);       
    };
    //-- Network error
    loader.onerror = function(e)
    {
        Ti.API.info('Network error: ' + JSON.stringify(e));
    };

    // Send the HTTP request
    loader.send();

    return  tableData;
};

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贱贱哒 2025-01-13 20:22:30

有了索引后,您应该能够通过它引用原始数据源。

Once you have your index, you should be able to reference your original data source by that.

月亮是我掰弯的 2025-01-13 20:22:30
       var favoriteButton = Ti.UI.createButton({
            title:'btn',
            //font:{fontFamily:'Helvetica Neue',fontSize:15},
            top:20,
            left:255,
            height:30,
            width:50,
            url:'../Images/favorite.png'
            //image:'../Images/favorite.png',
            name:categoryName,
            address:address;//address mention here
        });

       row.add(favoriteButton);

        favoriteButton.addEventListener('click', function(e)
         {
            var index = e.source.row;
            var name = e.source.name;
            var address = e.source.address; 
            alert('name'+name);

        });
    } 

我想这可能对你有很大帮助。

       var favoriteButton = Ti.UI.createButton({
            title:'btn',
            //font:{fontFamily:'Helvetica Neue',fontSize:15},
            top:20,
            left:255,
            height:30,
            width:50,
            url:'../Images/favorite.png'
            //image:'../Images/favorite.png',
            name:categoryName,
            address:address;//address mention here
        });

       row.add(favoriteButton);

        favoriteButton.addEventListener('click', function(e)
         {
            var index = e.source.row;
            var name = e.source.name;
            var address = e.source.address; 
            alert('name'+name);

        });
    } 

I think this might help you a lot.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文