3条状切换如何来回切换?谢谢 基本上我有一个下拉菜单,其中有三个不同的名称,每个名称都有自己特定的解释。
$scope.dropDownMenu = ["East","West","Central"];
$scope.selectedItem = $scope.dropDownMenu[0];
if($scope.selectedItem === "East")
$scope.selectedItem = $scope.dropDownMenu[1];
and so on.....
很容易在数组中的变量之间切换但是三个?我真的不知道怎么做。
答案 0 :(得分:3)
跟踪索引。
function toggle() {
var nextIndex = $scope.currentIndex + 1;
if (nextIndex >= $scope.dropDownMenu.length) {
nextIndex = 0;
}
$scope.selectedItem = $scope.dropDownMenu[nextIndex];
$scope.currentIndex = nextIndex;
}