在 table 上应用排序时如何更改范围变量?

How to change the scope variable when sorting applied on the table?

我正在使用带有 ng-repeat 的 Angular 数据表,其中所有列都可以排序。排序后,我想更改范围变量..可以实现吗?

简单示例如下:在我的例子中,我使用的是 JSON 个对象的数组

$scope.names = ['XYZ', 'DEF', 'ABC', 'IJK'];

对name字段应用数据表排序后,name filed的值应更改为:

$scope.names = ['ABC', 'DEF', 'IJK', 'XYZ'];

试试 orderBy 过滤器。例如,

ng-repeat="[{doc: 'bbb'}, {doc: 'aaa'}, {doc: 'ccc'}] | orderBy:'doc'"

会导致 [{doc: 'aaa'}, {doc: 'bbb'}, {doc: 'ccc'}]

在你的情况下你有字符串而不是数组中的对象所以我想你可以写 | orderBy

下面的代码正在运行...感谢@davidkonrad 对 dtInstance

的提示
 var sortedTableArray = [];
 var sortedJSON = []       
 DTInstances.getList().then(function(dtInstances) {
sortedTableArray.push(dtInstances.viewTable.DataTable.context[0].aiDisplay)

              sortedJSON = _.sortBy(unsortedList, function(obj){

                    return _.indexOf(_.toArray(sortedTableArray[0]), obj.id);
                });