2013-10-07 3 views
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); 
+0

정확히 무엇을하려고합니까? 모든 버튼을 클릭 할 때 전체 배열을 출력 하시겠습니까? 다음/이전을 출력 하시겠습니까? 버튼 클릭시 배열의 항목? – mwfire

답변

0

을 시도하고 나는이 임무에 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);