ich kein Programmierer von Beruf bin aber eher ein Bastler (Noob)ein Menü aus und Array erstellen, die einen Titel und einen Dateinamen enthält - Javascript/Appcelerator
I enthalten ein Menü aus Titel erstellen möchten in eine Anordnung. Ich habe das erfolgreich gemacht, indem ich das Array durchlaufen habe und den Wert bei jedem Schritt der Schleife als Titel für meine Buttons/Tabs verwendet habe.
Ich möchte jeder Schaltfläche einen Eventlistener mit einem Link zu eindeutigen Seiten hinzufügen. Ich wollte dies tun, indem ich die Beschriftung des Knopfes überprüfe und wenn es Wert A ist, dann bekommt es einen entsprechenden Link und so weiter, und weist es dann currentLink zu, auf das der Link [t] jedes Mal dann referenziert, wenn er durchgeht Schleife.
Ich denke, ich habe es fast funktioniert, aber nur auf das dynamische Hinzufügen eines Link-Bit verloren.
Jede Hilfe würde sehr geschätzt werden.
Hier ist mein Code:
//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);
});
}