Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 列数未知的angularsjs ng重复排序表_Javascript_Sorting_Angularjs_Angularjs Ng Repeat - Fatal编程技术网

Javascript 列数未知的angularsjs ng重复排序表

Javascript 列数未知的angularsjs ng重复排序表,javascript,sorting,angularjs,angularjs-ng-repeat,Javascript,Sorting,Angularjs,Angularjs Ng Repeat,我正试图按每列对一个表进行排序。该表每次有不同数量的行和列。问题在于谓词。所有重复的列都是名称“i”,我需要能够对它们进行单独排序 HTML: 这是你的电话号码 感谢您的回复。像这样更改声明 <th ng-repeat="header in headers"> <a href="" ng-click="$parent.predicate='item['+$index+']';$parent.reverse=!reverse">{{header}</a>

我正试图按每列对一个表进行排序。该表每次有不同数量的行和列。问题在于谓词。所有重复的列都是名称“i”,我需要能够对它们进行单独排序

HTML:

这是你的电话号码


感谢您的回复。

像这样更改声明

<th ng-repeat="header in headers">
     <a href="" ng-click="$parent.predicate='item['+$index+']';$parent.reverse=!reverse">{{header}</a>
</th>

注意:由于单元格都是字符串,这将按字符串字母顺序对所有列进行排序

希望它能给我们一些启示


内置的
orderBy
不适用于嵌套数据。您必须创建自己的过滤器,该过滤器是为您期望的数据定制的。谢谢,效果很好。我知道它与$index有关,但我就是找不到插入它的正确位置。谢谢你!是的,实际应用程序的数据是json格式的,所以我认为它们不会是字符串格式的。
function controller($scope) {
    $scope.headers = ["col1", "col2", "col3", "col4"];
    $scope.columns = [{value:'row1', item:['1','2','3','4']},
                      {value:'row2', item:['4','5','6','7']},
                      {value:'row3', item:['8','9','10','11']},
                      {value:'row4', item:['12','13','14','15']}];
    $scope.predicate = 'value';
}
<th ng-repeat="header in headers">
     <a href="" ng-click="$parent.predicate='item['+$index+']';$parent.reverse=!reverse">{{header}</a>
</th>