0

我正在制作一个小型应用程序,用于对用户拥有的点列表进行排序,类似于游戏排行榜。我已经在一组对象上设置了一个 ng-repeat,并在不同的选项上设置了一个 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 to smallest).

它适用于两个选项值,但不适用于第三个。知道为什么吗?

              <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>
4

1 回答 1

0

如果我正确理解这一点,那么您没有正确执行此操作。您的列表只会按“已创建”排序。orderBy 子句的第二个值只有在找到两个具有相同“created”的对象时才会起作用。对于 orderBy 子句中的第三个值也是如此。只有当两个项目具有相同的“创建”和相同的“读取”值时,才会使用它。
您将需要将 orderBy 设置为基于所选下拉设置的变量。您可以将其设置为您的选择绑定到的变量的名称。我认为这是您的 plnkr 中的讨论选择。

        <tr ng-repeat="user in users | discussionsSelect">
于 2015-01-26T19:20:01.833 回答