由许多领域的角度顺序

时间:2014-12-03 09:14:51

标签: angularjs

我想要三个字段的简单订单:

该订单中的名称,状态和所有者

到目前为止,我有这个:

<tr ng-repeat='data in model.tableData|filter:model.search|orderBy:"name":model.sorted.name'>

(当点击时,model.sorted.name正在切换true false),现在我看到我需要做这样的事情:

<tr ng-repeat="data in model.tableData|filter:model.search|orderBy:['name','status','owner']">

要处理多个字段,但我怎样才能更改它, 例如,状态从true到false,就像我使用单一的那样?

1 个答案:

答案 0 :(得分:1)

您可以使用&#39;!&#39;即:

 <tr ng-repeat="data in model|filter:model.search|orderBy:['name','!status','owner']">

请在下面演示

&#13;
&#13;
var app = angular.module('app', []);

app.controller('homeCtrl', function($scope) {


  $scope.model = [{
      'name': 'a1',
      'status': true,
      'owner': 'as'
    }, {
      'name': 'a1',
      'status': false,
      'owner': 'as'
    }, {
      'name': 'a1',
      'status': false,
      'owner': 'as'
    }


  ]

});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
  <div ng-controller="homeCtrl">
    <h3> By status reverse </h3>
    <table>
      <tr ng-repeat="data in model|filter:model.search|orderBy:['!status','name','owner']">
        <td>{{data.status}}|{{data.owner}}| {{data.name}}</td>
      </tr>
    </table>
    <hr/>

    <h3> By status</h3>
    <table>
      <tr ng-repeat="data in model|filter:model.search|orderBy:['status','name','owner']">
        <td>{{data.status}}|{{data.owner}}| {{data.name}}</td>
      </tr>
    </table>
  </div>
</div>
&#13;
&#13;
&#13;