Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7413217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:39:43+00:00 2026-05-29T06:39:43+00:00

Hope this makes sense, I am using Titanium mobile to build an iPhone app.

  • 0

Hope this makes sense, I am using Titanium mobile to build an iPhone app. I have an array of 100 items each item has an DishID and an DishTitle, I show the DishTitle in a tableview and on the event listener I need to pass the DishID and use alert it for now on the event listener I will later do something with the items ID this is my code so far:

var dishes = eval(this.responseText);

for (var i = 0; i < dishes.length; i++)
            {

                DishID[i] = dishes[i].DishID;

                var row = Ti.UI.createTableViewRow();
                    row.selectedBackgroundColor = '#fff';
                    row.height = 30;
                    row.className = 'datarow';
                    row.clickName = 'row';

                // Create the label to hold the screen name
                name[i] = Titanium.UI.createLabel({
                    color:'#000',
                    font:{fontSize:16,fontWeight:'bold', fontFamily:'Arial'},
                    left:5,
                    top:2,
                    height:30,
                    width:200,
                    text:dishes[i].DishTitle
                });

                name[i].addEventListener('click', function(e){

                                 alert(DishID[i]);
                            });

            }

The issue I am having I keep getting the same ID 208 no matter which Label I click, am I doing something wrong ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:39:44+00:00Added an answer on May 29, 2026 at 6:39 am

    You’ve got a scope / closure issue. By the time the ‘click’ happens, i=208. I find it best to put the eventListener on the table, and custom attribue on the row:

    var table = Ti.UI.createTableView();
    var rows = [];
    
    for(var i = 0; i < dishes.length; i++) {
    
        var row = Ti.UI.createTableViewRow({
            selectedBackgroundColor : '#fff',
            height : 30,
            className : 'datarow'
        });
    
        row.dishId = dishes[i].DishID;
    
        // Create the label to hold the screen name
        var label = Ti.UI.createLabel({
            color : '#000',
            font : {
                fontSize : 16,
                fontWeight : 'bold',
                fontFamily : 'Arial'
            },
            left : 5,
            top : 2,
            height : 30,
            width : 200,
            text : dishes[i].DishTitle
        });
    
        row.add(label)
    
        rows.push(row);
    }
    
    table.setData(rows);
    
    table.addEventListener('click', function(e) {
        alert(e.row.dishId);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope this makes sense. I have a Windows Phone 7 app that is
I have an issue with jQuery and Safari (5.03). Hope this makes sense. I
I hope this makes sense. I'm using Java with the Slick2d library, that probably
I hope this makes sense. I have a ASP.NET web application that uses Entity
Bit tricky to communicate but hope this makes sense. I have 8 div containers
Hope this makes sense... Is there a simple way to return a set of
I am just getting started with expression trees so I hope this makes sense.
I'm developing an iPhone app at the moment using Appcelerator Titanium which has 3
I have this idea for an iPhone app and the first time the app
hope to get some help here because this is something that really makes me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.