【问题标题】:html table sorting doesn't work with angularJShtml表格排序不适用于angularJS
【发布时间】:2014-07-23 23:56:48
【问题描述】:

我正在尝试使用 angularJS 根据列名对表进行排序,但我的表没有反应。 这是我的 html 表:

<table class="table">
    <tr > 
        <th ng-repeat="(i,facet) in voies.parameters.facet"><button type="button" class="btn btn-success" ng-click="toggleSort(i)">{{voies.parameters.facet[i]}}</button></th>
    </tr> 
<tr  ng-repeat="(i,fields) in voies.records" | orderBy:sortColumn:reverse>
  <td>{{voies.records[i].fields.joueur}}</td>
  <td>{{voies.records[i].fields.name}}</td>
  <td>{{voies.records[i].fields.point}}</td>
  <td>{{voies.records[i].fields.club}}</td>
  <td>{{voies.records[i].fields.country}}</td>
  <td>{{voies.records[i].fields.vote}}</td>
  <td>{{voies.records[i].fields.poste}}</td>
  <td>{{voies.records[i].fields.continent}}</td>
</tr>

这是我的 JS:

$scope.toggleSort = function(index) {
    console.info(index);
if($scope.sortColumn === $scope.voies.parameters.facet[index]){
    $scope.reverse = !$scope.reverse;
}                    
    $scope.sortColumn = $scope.voies.parameters.facet[index];
};

我的数据是从这个链接加载的:dataBase

欢迎任何帮助!

【问题讨论】:

  • 也许把它扔进 JsFiddle (jsfiddle.net),编辑帖子,然后添加链接?
  • 对我来说看起来不错,除了第二个 ng-repeat 中的错字:jsfiddle.net/n36b9/4

标签: angularjs html sorting html-table


【解决方案1】:

你的代码works perfectly well当我修正这个错字时:

<tr ng-repeat="(i,fields) in voies.records" | orderBy:sortColumn:reverse>

应该是

<tr ng-repeat="(i,fields) in voies.records | orderBy:sortColumn:reverse">

另外,请注意ng-repeat 迭代器为您提供实际对象(“facet”、“fields”),因此您不需要使用索引器。而不是这个:

<td>{{voies.records[i].fields.joueur}}</td>

你应该简单地使用:

<td>{{fields.joueur}}</td>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多