gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 10:25:48 25 4
gpt4 key购买 nike

我不是一个职业程序员,而是一个修补匠(菜鸟)

我想根据数组中包含的标题创建一个菜单。我通过循环数组并使用循环每一步的值作为按钮/选项卡的标题成功地完成了此操作。

我想向每个按钮添加一个事件监听器,并提供指向唯一页面的链接。我本来打算通过检查按钮的标签来做到这一点,如果它是值 A,那么它会获得相应的链接,依此类推,然后将其分配给 currentLink,然后每次通过 theLink[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);
});

}

最佳答案

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

http://download.oracle.com/javase/1.4.2/docs/api/java/util/HashSet.html

我也会改变这个......

  //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';
}
}

这让我很烦恼:)

关于javascript - 从包含标题和文件名的数组创建菜单 - Javascript/Appcelerator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4345907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com