重新排序某些元素后如何重置 ng 重复块?



我有一个ng-repeat,它使用数组作为数据。现在从 UI 中,我使用拖放对元素重新排序。我有一个取消按钮,它应该重置 ng-repeat,以便根据数组的顺序恢复元素的顺序。我不知道该怎么做。有没有办法从angularjs或使用jquery来实现这一点?

一种方法是更改您的$scope变量。通过执行以下操作,您保留了数组顺序并触发 ng-repeat 以重新渲染。

$scope.reset = function(){
// $scope.data is the variable that holds the array in ng repeat
$scope.data =  angular.copy($scope.data)
}

最新更新