从和数组创建包含标题和文件名的菜单-Javascript/Appcelerator

从和数组创建包含标题和文件名的菜单-Javascript/Appcelerator,javascript,android,appcelerator-mobile,Javascript,Android,Appcelerator Mobile,我不是一个程序员,而是一个修补匠 我想从数组中包含的标题创建一个菜单。 我已经成功地完成了这项工作,在数组中循环,并使用循环的每个步骤的值作为我的按钮/选项卡的标题 我想为每个按钮添加一个eventlistener,其中包含指向唯一页面的链接。我本来打算通过检查按钮的标签来实现这一点,如果它是值A,那么它会得到一个相应的链接,依此类推,然后将其分配给currentLink,该链接在每次通过循环时都会被链接[t]引用 我想我几乎让它工作了,但只是在动态添加链接位时迷失了方向 任何帮助都将不胜感激

我不是一个程序员,而是一个修补匠

我想从数组中包含的标题创建一个菜单。 我已经成功地完成了这项工作,在数组中循环,并使用循环的每个步骤的值作为我的按钮/选项卡的标题

我想为每个按钮添加一个eventlistener,其中包含指向唯一页面的链接。我本来打算通过检查按钮的标签来实现这一点,如果它是值A,那么它会得到一个相应的链接,依此类推,然后将其分配给currentLink,该链接在每次通过循环时都会被链接[t]引用

我想我几乎让它工作了,但只是在动态添加链接位时迷失了方向

任何帮助都将不胜感激

这是我的密码:

//function to check the label name and assign the relevant filename to be passed on
    function winLink(currentTab){
     if (currentTab == 'Audio'){
      currentLink = 'audioPlayer.js';
      pageWin.url = currentLink;

     } else{
      if (currentTab == 'Images'){
      currentLink = 'images.js';
      }
     } 
    }

//function to change button colours according to active button
function button_colour(e){
 if (clickedButton == ''){
  clickedButton = e.source; 
  clickedButton.backgroundImage = tabBckImgSel;

 } else {
  clickedButton.backgroundImage = tabBckImg;
  clickedButton = e.source; 
  clickedButton.backgroundImage = tabBckImgSel;
  }
}


    //Array that contains button names
    var tabsArray =['Audio','Images','Video','Info','Materials','Further Reading','Map'];

//loop through array and create a holder, label and eventlistener to attach
for (var t=0;t<tabsArray.length;t++) {
 //create view to act as button/tab area
 viewButton[t] = Titanium.UI.createView({
  borderWidth:1,
  borderColor: tabBrdrColour,
  width:tabWidth,
  height:tabHeight,
  left:leftTab + padding
 });

 //add the tab to the main menu view/area
 menu.add(viewButton[t]);

 //increment the left position for the next button to be placed to the right of the previous button
 leftTab = viewButton[t].left + tabWidth;

 Buttonlabel[t] = Titanium.UI.createLabel({
  text: tabsArray[t],
  font:{fontSize:13},
  color:'#fff',
  width:labelWidth,
  textAlign:'center',
  height:'auto'
 });

 viewButton[t].add(Buttonlabel[t]);

    //pre declared variable  to hold the title of the current label
 currentTab = tabsArray[t];
//call to function to check label and set the relevant file to load
 winLink(currentTab);

 viewButton[t].addEventListener('singletap', function(e)
  {

  button_colour(e);
  win.add(pageWin);
var theLink[t] = currentLink;
  // alert (' Current link' + currentLink);
 });

}

您需要的是哈希表吗?它将允许您动态创建和使用这些链接

我也会改变这个

  //function to check the label name and assign the relevant filename to be passed on
function winLink(currentTab){
 if (currentTab == 'Audio'){
  currentLink = 'audioPlayer.js';
  pageWin.url = currentLink;
  } else{
  if (currentTab == 'Images'){
  currentLink = 'images.js';
  }
 } 
}

这让我心烦:

       //function to check the label name and assign the relevant filename to be passed on
function winLink(currentTab){
 if (currentTab == 'Audio'){
  currentLink = 'audioPlayer.js';
  pageWin.url = currentLink;
  } else if(currentTab == 'Images'){
  currentLink = 'images.js';
  }
 }