我正在尝试按每一列对表格进行排序。该表每次都有不同数量的行和列。问题出在谓词上。所有重复的列都是名称“i”,我需要能够单独对它们进行排序。
HTML:
<table>
<thead>
<th><a href="" ng-click="predicate='value';reverse=!reverse">name</a></th>
<th ng-repeat="header in headers"><a href="" ng-click="predicate='i';reverse=!reverse">{{header}}</a></th>
</thead>
<tbody>
<tr ng-repeat="v in columns | orderBy:predicate:reverse">
<td>{{v.value}}</td>
<td ng-repeat="i in v.item">{{i}}</td>
</tr>
</tbody>
</table>
控制器:
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';
}
这是jsfiddle。
感谢您的回复。