1

我需要使用 orderBy 在 AngularJs 排序功能上显示加载器小部件。

我有大约 10 个选项可以为 ex 排序。按名称,按价格等。在我的页面上,我加载了大约 100 个对象,因此,排序需要一些时间来反映。因此,我需要在此时间间隔内显示一个加载器小部件。

基本上,一旦我单击所需的选项(即按名称、按价格等),加载程序小部件就会显示,一旦排序完成,加载程序就会消失并呈现页面。

如果有人可以通过此更改修改下面的小提琴,那就太好了。

http://www.jsfiddle.net/vjF2D/

function ContactListCtrl($scope){
  $scope.sortorder = 'surname';
  $scope.contacts = 
  [
     { "name":"Richard", "surname":"Stallman", "telephone":"1234 98765" },
     { "name":"Linus", "surname":"Torvalds", "telephone":"2345 87654" },
     { "name":"Donald", "surname":"Knuth", "telephone":"3456 76543" }
  ];
 }
------------------------------------------
<div ng-app ng-controller="ContactListCtrl">
<h1>AngularJS Sorting Example</h1>

<select ng-model="sortorder">
  <option value="surname">Surname (A-Z)</option>
  <option value="-surname">Surname (Z-A)</option>
</select>

<table class="contacts">
  <tr>
    <th>Name</th>
    <th>Telephone</th>
  </tr>

  <tr ng-repeat="contact in contacts | orderBy:sortorder">
    <td ng-class-even="'even'">{{contact.name}}, {{contact.surname}}</td>
    <td ng-class-even="'even'">{{contact.telephone}}</td>
  </tr>
</table>
</div>

提前致谢 !!!

4

2 回答 2

1

我建议你angularjs-spinner,看看GitHub来源

或者:

HTML

<div ng-controller="ContactListCtrl">

<h1>AngularJS Sorting Example</h1>

    <select ng-model="sortorder">
        <option value="surname">Surname (A-Z)</option>
        <option value="-surname">Surname (Z-A)</option>
    </select>
    <table class="contacts">
        <tr>
            <th>Name</th>
            <th>Telephone</th>
        </tr>
        <tr ng-repeat="contact in contacts | orderBy:sortorder" repeat-done="layoutDone()" >
            <td ng-class-even="'even'">{{contact.name}}, {{contact.surname}}</td>
            <td ng-class-even="'even'">{{contact.telephone}}</td>
        </tr>
    </table>
    <div id="veil" ng-show="isLoading"></div>
    <div id="feedLoading" ng-show="isLoading">Loading...</div>
</div>

JS

var app = angular.module('myModule', []);

app.controller('ContactListCtrl', function ($scope) {
    $scope.sortorder = 'surname';
    $scope.contacts = [{
        "name": "Richard",
        "surname": "Stallman",
        "telephone": "1234 98765"
    }, {
        "name": "Linus",
        "surname": "Torvalds",
        "telephone": "2345 87654"
    }, {
        "name": "Donald",
        "surname": "Knuth",
        "telephone": "3456 76543"
    }];

    $scope.setLoading = function (loading) {
        $scope.isLoading = loading;
    }


    $scope.layoutDone = function () {
        console.log("vvvvv");
        $scope.setLoading(false);       
    }

    $scope.loadFeed = function(url) {
            $scope.setLoading(true);

        }

    $scope.loadFeed();
});



app.directive('repeatDone', function() {
        return function(scope, element, attrs) {
            if (scope.$last) { // all are rendered
                scope.$eval(attrs.repeatDone);
            }
        }
    })

编辑后的 ​​DemoFiddle

于 2013-10-14T06:59:38.040 回答
0

感谢Maxim Shoustin解决了我的疑问。感谢他提供以下工作 jsfiddle 示例:

http://www.jsfiddle.net/vjF2D/11

var app = angular.module('myModule', []);

app.controller('ContactListCtrl', function ($scope, $timeout, $filter) {

var sortingOrder = 'name';
$scope.sortingOrder = sortingOrder;



$scope.sortorder = 'surname';
$scope.contacts = [{
    "name": "Richard",
    "surname": "Stallman",
    "telephone": "1234 98765"
}, {
    "name": "Donald",
    "surname": "Knuth",
    "telephone": "3456 76543"
}, {
    "name": "Linus",
    "surname": "Torvalds",
    "telephone": "2345 87654"
}];

$scope.setLoading = function (loading) {
    $scope.isLoading = loading;
}


$scope.layoutDone = function (value) {
    console.log(value);
    $scope.setLoading(true);

     $timeout(function() { 
    // take care of the sorting order
    if ($scope.sortingOrder !== '') {

        if(value == 'surname'){
        $scope.contacts = $filter('orderBy')($scope.contacts, $scope.sortingOrder, false);
        }
        else if(value == '-surname'){
        $scope.contacts = $filter('orderBy')($scope.contacts, $scope.sortingOrder, true);
        }
        else{
          $scope.contacts = $filter('orderBy')($scope.contacts, $scope.sortingOrder, false);  
        }
    }




            $scope.setLoading(false);
        }, 1000);


  }

   $scope.loadFeed = function(url) {       
  $scope.setLoading(true);          
 }

    $scope.loadFeed();
 }); 



app.directive('repeatDone', function() {
    return function(scope, element, attrs) {
        if (scope.$last) { // all are rendered
            scope.$eval(attrs.repeatDone);
        }
    }
})
于 2013-10-14T11:28:27.807 回答