如何来回切换 3 个条件?谢谢 基本上我有一个下拉菜单,其中有三个不同的名称,每个名称都有自己特定的解释。
$scope.dropDownMenu = ["East","West","Central"];
$scope.selectedItem = $scope.dropDownMenu[0];
if($scope.selectedItem === "East")
$scope.selectedItem = $scope.dropDownMenu[1];
and so on.....
在数组中的变量之间切换很容易,但是三个?我真的不知道怎么办。
- 1.东部之后的下一个信息可以是西部或中部,而不仅仅是西部
- 西部之后的下一个信息可以是东部或中部,而不仅仅是 中环
- Central 之后的下一个信息可以是 East 或 West,而不仅仅是 East
最佳答案
跟踪索引。
function toggle() {
var nextIndex = $scope.currentIndex + 1;
if (nextIndex >= $scope.dropDownMenu.length) {
nextIndex = 0;
}
$scope.selectedItem = $scope.dropDownMenu[nextIndex];
$scope.currentIndex = nextIndex;
}
关于javascript - 如何在数组中的三个不同变量之间切换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42615521/