Angularjs:排序在 Chrome 和 Firefox 浏览器中显示不同的结果

2024-05-07

您好,我在 chrome 和 firefox 浏览器中得到不同的数据排序结果。 Firefox 显示正确的一个。

HTML :

<table class="datatable">
              <thead>
                <tr>
                  <th width="5%" class="Rank">Rank&nbsp;<a ng-click="sort_by('Rank')"><i class="icon-sort" ng-show="pagedItems[currentPage].length > 1"></i></a></th>
                  <th width="10%" class="Interviews">Interviews&nbsp;<a ng-click="sort_by('Interviews')"><i class="icon-sort" ng-show="pagedItems[currentPage].length > 1"></i></a></th>
                  <th width="25%" class="Dealership">Dealership&nbsp;<a ng-click="sort_by('Dealership')"><i class="icon-sort" ng-show="pagedItems[currentPage].length > 1"></i></a></th>
                  <th width="15%" class="Satisfaction">Overall Satisfaction&nbsp;<a ng-click="sort_by('Satisfaction')"><i class="icon-sort" ng-show="pagedItems[currentPage].length > 1"></i></a></th>
                  <th width="15%" class="Loyalty">Loyalty&nbsp;<a ng-click="sort_by('Loyalty')"><i class="icon-sort" ng-show="pagedItems[currentPage].length > 1"></i></a></th>
                </tr>
              </thead>
              <tbody>
                <tr ng-repeat="item in pagedItems[currentPage] | orderBy:sortingOrder:reverse">
                    <td>{{item.Rank}} - {{item.$$hashKey}}</td>
                    <td>{{item.Interviews}}</td>
                    <td>{{item.Dealership}}</td>
                    <td>{{item.Satisfaction | number:1}}</td>
                    <td>{{item.Loyalty}}</td>
                </tr>
            </tbody>

我最初使用 Rank 进行排序:

角度控制器代码:

$scope.sortingOrder = sortingOrder;
$scope.reverse = false;

Firefox 中的结果:排名列显示带有哈希键值的排名

Chrome 结果:排名列显示带有哈希键值的排名

这里我用Rank排序。具有相同排名的数据按照 $$hashkey 排序。 Firefox 提供 $$hashkey 以便获取数据。 Chrome 在给出哈希键时将第二条记录放在最后。

我无法理解为什么会发生这种情况。有什么办法可以避免吗?

提前致谢。


我在谷歌浏览器中遇到了同样的问题。 补救措施是在页面加载时设置初始排序字段。

我以前没有这样做:

$scope.items = {[$data]}    



        $scope.mySortFunction = function(item) {
            if(isNaN(item[$scope.sortExpression]))
                return item[$scope.sortExpression];
            return parseInt(item[$scope.sortExpression]);
        }

我把上面的改成这样:

$scope.items = {[$data]}    

        //we want the 1st load to be sorted by sort_code
        $scope.sortExpression = 'sort_code';

        $scope.mySortFunction = function(item) {
            if(isNaN(item[$scope.sortExpression]))
                return item[$scope.sortExpression];
            return parseInt(item[$scope.sortExpression]);
        }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Angularjs:排序在 Chrome 和 Firefox 浏览器中显示不同的结果 的相关文章

随机推荐