我想要具有重新排列表中行的功能(使用拖放对行进行排序)。 模型中行排列的索引也应该改变。
我怎样才能做类似的事情:http://jsfiddle.net/tzYbU/1162/ 使用 Angular Directive(指令)?
我正在生成表:
<table id="sort" class="table table-striped table-bordered">
<thead>
<tr>
<th class="header-color-green"></th>
<th ng-repeat="titles in Rules.Titles">{{titles.title}}</th>
</tr>
</thead>
<tbody ng-repeat="rule in Rules.data">
<tr>
<td class="center"><span>{{rule.ruleSeq}}</span></td>
<td ng-repeat="data in rule.ruleData">{{statusArr[data.value]}}</td>
</tr>
</tbody>
</table>
最佳答案
我做到了。请参阅下面我的代码。
HTML
<div ng:controller="controller">
<table style="width:auto;" class="table table-bordered">
<thead>
<tr>
<th>Index</th>
<th>Count</th>
</tr>
</thead>
<tbody ui:sortable ng:model="list">
<tr ng:repeat="item in list" class="item" style="cursor: move;">
<td>{{$index}}</td>
<td>{{item}}</td>
</tr>
</tbody>{{list}}
<hr>
</div>
指令 (JS)
var myapp = angular.module('myapp', ['ui']);
myapp.controller('controller', function ($scope) {
$scope.list = ["one", "two", "thre", "four", "five", "six"];
});
angular.bootstrap(document, ['myapp']);
关于javascript - 在 angularjs 中对表的行进行排序或重新排列(拖放),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18614695/