我在ng-repeat中有一个很棒的项目列表,每个项目都有一个向上和向下按钮.我只想要向上按钮将列表项向上移动一个位置,向下按钮应将其向下移动一个位置.问题是我收到一条错误,上面写着"无法读取未定义的属性'NaN'." 似乎"位置"在第二行未定义.我该怎么做才能解决这个问题?
继承人我正在使用的javascript(感谢Rishul Matta):
$scope.moveUp = function(ind, position) {
$scope.temp = $scope.list[position - 1];
$scope.list[position - 1] = $scope.list[position];
$scope.list[position = temp];
};
Run Code Online (Sandbox Code Playgroud)
这是我的HTML:
<ul>
<li class="steps" ng-repeat="step in selectedWorkflow.Steps track by $index" ng-class="{'words' : step.Id != selectedStep.Id, 'selectedWords' : step.Id == selectedStep.Id}" ng-model="selectedWorkflow.Step" ng-click="selectStep(step, $index); toggleShow('showSubStep'); toggleShow('showEditBtn')">
{{step.Name}}
<input class="orderUpBtn" type="button" ng-click="moveUp($index, step)" style="z-index:50" value="U" />
<input class="orderDownBtn" type="button" style="z-index:50" value="D" />
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
谢谢!