浏览器中显示不同的结果

浏览器中显示不同的结果

本文介绍了Angularjs:排序在 chrome 和 firefox 浏览器中显示不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 chrome 和 firefox 浏览器中得到不同的数据排序结果.Firefox 显示正确.

HI I am getting different result in chrome and firefox browser of sorting of data. Firefox shows correct one.

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>

我最初用排名排序:

角度控制器代码:

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

Firefox 中的结果:Rank 列显示带有 Hashkey 值的 Rank

Result in Firefox : Rank Column shows Rank with Hashkey value

Chrome 结果:Rank 列显示带有 Hashkey 值的 Rank

Chrome Result : Rank Column shows Rank with Hashkey value

这里我用Rank排序.具有相同等级的数据在其 $$hashkey 之后排序.Firefox 提供 $$hashkey 以获取数据.Chrome 在给出哈希键时将第二条记录放在最后.

Here I am sorting with Rank. The Data with Same Rank gets sorted after their $$hashkey. Firefox gives $$hashkey in order it gets data. where as Chrome palce the second record to last in giving hash key.

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

I am not able to understand why this is happening. is there any way i can avoid.

提前致谢.

推荐答案

我在 Google Chrome 中遇到了同样的问题.补救措施是在页面加载时设置初始排序字段.

I had the same problem in Google Chrome.The remedy was to set the initial sort field upon page load.

我以前没有这样做:

$scope.items = {[$data]}



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

我把上面的改成了这样:

I changed the above to this:

$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]);
        }

这篇关于Angularjs:排序在 chrome 和 firefox 浏览器中显示不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 15:35