我想显示上一个和下一个字, 当前一个是'fuga'时,请让下一个是第一个('hoge'),同样的事情,当前的那个是第一个,prev应该是列表中的最后一个 - 'fuga'
你可以帮帮我吗?请[http://jsfiddle.net/zeck/L8Snx/][1]
答案 0 :(得分:1)
这可能是您正在寻找的。工作小提琴:http://jsfiddle.net/L8Snx/37/
<强> HTML 强>
<div>
<strong>Previous:</strong> {{getPrev().name}}
<strong>Current:</strong> {{current.name}}
<strong>Next:</strong> {{getNext().name}}
</div>
<强>的JavaScript 强>
$scope.getNext = function() {
var i = $scope.getIndex($scope.current.index, 1);
return $scope.dataSet[i];
};
$scope.getPrev = function() {
var i = $scope.getIndex($scope.current.index, -1);
return $scope.dataSet[i];
};