title: How to get index (or value) of DropDownButton selection
body: <p>I have a DownDownButton that I've populated from an array containing project names and ids. The list shows the project name, but I'd like to get the project id. The variable "projects" looks like this:</p>
  
  <blockquote>
    <p>[Object { name="Project A", id="1325"}, Object { name="Project B", id="5241"}, Object { name="Project C", id="3224"}]</p>
  </blockquote>
  
  <p>This code creates the MenuItem for the button correctly, but how do I set the variable projId in the onClick event?    </p>
  
  <pre><code>for (i = 0; i &lt; projects.length; i++) {
      menuProjects.addChild(new MenuItem({
          label: projects[i].name,
          onClick: function () {
              projId = ?;
          }
     }));
  }
  </code></pre>
  
  <p>I've tried using "projId= projects[i].id;", but that gives me an error since i is now 3. What's the correct syntax to do this?</p>
  
  <p><strong>-- Edit --</strong></p>
  
  <p>This is how I got it to work using both cookie's and Merrick's answers.</p>
  
  <pre><code>for (i = 0; i &lt; projects.length; i++)
      (function (x) {
          menuProjects.addChild(new MenuItem({
              label: projects[i].name,
              onClick: function () {
                  projId = projects[x].id;
              }
          }));
      } (i));
  </code></pre>