1

我是学生,所以很抱歉问了这么简单的问题。我正在尝试制作一个“下一个”和“上一个”按钮,一次循环一个数组。

var food = ["pasta", "Salad", "Apple", "Pizza"];
    counter=0;

    var displayAlert = function(){ 
        for (var i=0, item; i<food.length; i++) {
        item = food[i];
        quoteText.text=food[i];
}   
};      

    var quoteView = Ti.UI.createView({
    backgroundColor: "#fff",
    height: 150,
    top: 50,
    left: 20,
    right: 20,
    borderRadius: 5

});


var quoteText = Ti.UI.createLabel({
    text: "click below to begin",
    font: {fontSize: 20, fontFamily: "Arial"},
    textAlign: "center"
});
    quoteView.add(quoteText);
    mainWindow.add(quoteView);



buttonPrevious.addEventListener("click", displayAlert);
buttonNext.addEventListener("click", displayAlert);
4

1 回答 1

0

所以我已经和我的导师一起完成了代码,虽然我会在这个作业中获得零分,但其他人可能会从我的不幸中受益。

var food = ["pasta", "Salad", "Apple", "Pizza"];
    counter=0;

    var displayAlert = function(){
        console.log (counter);
    quoteText.text=food[counter];
    if (counter === food.length-1){
        counter=0;  
    }
    else {counter=counter+1};
};      
    var getPrevious = function(){
        quoteText.text=food[counter];
    if (counter === 0){
        counter=food.length-1;
    }
    else {counter=counter-1};

};
    var quoteView = Ti.UI.createView({
    backgroundColor: "#fff",
    height: 150,
    top: 50,
    left: 20,
    right: 20,
    borderRadius: 5

});


var quoteText = Ti.UI.createLabel({
    text: "click below to begin",
    font: {fontSize: 20, fontFamily: "Arial"},
    textAlign: "center"
});
    quoteView.add(quoteText);
    mainWindow.add(quoteView);
于 2013-10-08T05:31:00.017 回答