如何在 Angular JS ng-repeat 中传递用于排序表格数据的值(true 或 false)

How to pass value (true or false) for sorting tabular data in Angular JS ng-repeat

我想通过传递来自下拉框的值来确定 ng-repeat 的 ascending/descending 属性。

我定义了一个名为 "asdc" 的变量,其值由下拉框决定。此变量应确定 table 将按升序还是降序排序。该变量已在 AngularJS 控制器中创建,因此我不在此处 post。我正在粘贴下面的代码。它不是这样工作的。我想知道我错过了什么。

这是我要排序的table。

<tr ng-repeat="technology in technologies | limitTo: rowlimit | orderBy: sortby : adsc" >
<td>{{technology.name | uppercase}}</td>
</tr>

这是下拉框。它将 adsc 的值定义为 true 或 false,并将该值传递给 "adsc".

<select ng-model="adsc">
    <option value="true">Asc</option>
    <option value="false">Dsc</option>
</select>

使用 ng-options 绑定到字符串以外的东西:

在控制器中:

$scope.directions = [
  {
    value: false,
    label: 'Asc'
  },
  {
    value: true,
    label: 'Desc'
  }
];    

在视图中:

<select name="direction" ng-model="adsc" 
        ng-options="direction.value as direction.label for direction in directions">
</select>

这里a plunkr演示了它的用法。

另外,请注意传递 true 将按降序排序,而不是升序。