AngularJS:选项 Select 上的 OrderBy 过滤器
AngularJS: OrderBy Filter on Option Select
我正在制作一个小应用程序,用于对用户拥有的点数列表进行排序,类似于游戏排行榜。我已经在对象数组上设置了一个 ng-repeat,在不同的选项 selects 上设置了一个 ng-show 以显示列表中的跨度。跨度显示不同的分数。
我在 ng-repeat 上添加了一个 orderBy 过滤器,因此列表是从最大到最小过滤的。 For instance, when the option select of 'Threads Created' is chosen, then the scores for 'Post Read' and 'Posts Replied' are hidden and the list is sorted by the number of Threads Created (largest到最小)。
它适用于两个选项值,但不适用于第三个。知道为什么吗?
<tr ng-repeat="user in users | orderBy:['-created','-read','-replied']">
<td> {{user.index}} </td>
<td> {{user.firstName}} {{user.lastName}}</td>
<td>
<span ng-show='discussionsSelect == "created"'>{{ user.created }}</span>
<span ng-show='discussionsSelect == "read"'>{{ user.read }}</span>
<span ng-show='discussionsSelect == "replied"'>{{ user.replied }}</span>
</td>
</tr>
如果我的理解正确,那说明您没有正确执行此操作。您的列表只会按 'created' 排序。 orderBy 子句的第二个值只有在找到具有相同 'created' 的两个对象时才会起作用。同样对于 orderBy 子句中的第三个值。只有当两个项目具有相同的 'created' 和相同的 'read' 值时才会使用它。
您将需要使 orderBy 成为一个根据所选下拉菜单设置的变量。您可以将其设置为您的 select 绑定到的变量的名称。我认为这是在你的 plnkr 中选择的讨论。
<tr ng-repeat="user in users | discussionsSelect">
我正在制作一个小应用程序,用于对用户拥有的点数列表进行排序,类似于游戏排行榜。我已经在对象数组上设置了一个 ng-repeat,在不同的选项 selects 上设置了一个 ng-show 以显示列表中的跨度。跨度显示不同的分数。
我在 ng-repeat 上添加了一个 orderBy 过滤器,因此列表是从最大到最小过滤的。 For instance, when the option select of 'Threads Created' is chosen, then the scores for 'Post Read' and 'Posts Replied' are hidden and the list is sorted by the number of Threads Created (largest到最小)。
它适用于两个选项值,但不适用于第三个。知道为什么吗?
<tr ng-repeat="user in users | orderBy:['-created','-read','-replied']">
<td> {{user.index}} </td>
<td> {{user.firstName}} {{user.lastName}}</td>
<td>
<span ng-show='discussionsSelect == "created"'>{{ user.created }}</span>
<span ng-show='discussionsSelect == "read"'>{{ user.read }}</span>
<span ng-show='discussionsSelect == "replied"'>{{ user.replied }}</span>
</td>
</tr>
如果我的理解正确,那说明您没有正确执行此操作。您的列表只会按 'created' 排序。 orderBy 子句的第二个值只有在找到具有相同 'created' 的两个对象时才会起作用。同样对于 orderBy 子句中的第三个值。只有当两个项目具有相同的 'created' 和相同的 'read' 值时才会使用它。
您将需要使 orderBy 成为一个根据所选下拉菜单设置的变量。您可以将其设置为您的 select 绑定到的变量的名称。我认为这是在你的 plnkr 中选择的讨论。
<tr ng-repeat="user in users | discussionsSelect">