有没有办法暂停循环直到用户向右或向左滑动?

Is there a way to pause a loop until a user swipes right or left?

我需要一种简单的方法来暂停我的 while 循环,直到用户向左滑动。现在我的 while 循环 运行 遍历我所有的对象而不给它们显示的机会,所以只有最后一个最终显示。我正在寻找的是让我的函数 运行 一次并等待用户向右或向左滑动然后再次通过 while 循环的东西。 在正确方向上的任何帮助将不胜感激。 Google还没有返回我想要的

很难准确理解您想要什么,但听上去,您想要在循环中滑动 运行 一次然后停止,直到您再次滑动。您可以做的是消除 while 循环,只跟踪通过对象数组的步骤。类似的东西(非常简陋,但会给你一个大概的想法):

// hold onto your position (the item currently displayed) in the module
var objIndex = 0;

// when you swipe to the next, increment the index and display the next item you fetched from the api
function moveNext() {
    objIndex += 1;
    displayData();
}
// if you can go backwards with a swipe, decrement the index and display the previous item you fetched from the db
function movePrev() {
    objIndex -= 1;
    displayData();
}

function displayData() {
    // your code to display your item on screen using the index you've saved in the module
}