2016-02-05 65 views
0

我试图显示按每个元素的位置降序排列的数组($scope.stored_questions_clusters),问题是我没有得到所需的结果。AngularJS orderBy过滤器不按预期方式工作

在这个例子中,我做了一个ng-repeat = "question cluster stored in clusters questions | orderBy '- question_cluster.position'",在每次迭代中,我创建一个带有bootstrap的面板,在那里打印位置,所以我期望的是按照它们的位置排序的列表,但是我没有得到这个...

这里是我使用的代码:

<div style="margin-top:30px;" ng-show="mostrarPreguntas==true"> 
    <div ng-repeat="question_cluster in stored_questions_clusters | orderBy:'-question_cluster.position'" class="col-xs-8 col-xs-offset-2"> 
    <div class="panel panel-default"> 
     <div class="panel-heading"> 
     <div class="row"> 
      <div class="col-xs-11"> 
      <h3>{{question_cluster.position}}.- {{question_cluster.title}}</h3> 
       </div> 
       . 
       . 
       . 

这是结果:

sort_by_error

这个我s各自元素的console.log:

enter image description here

+0

'question_cluster.position'是'数字'还是'字符串? – gtlambert

+0

它应该是一个整数......我猜...这是我第一次使用AngularJS和JSON响应......有没有办法检查它? – OiciTrap

+0

我的意思是,如果在使用.class的Rails中有方法,无论如何,它是一个整数,我把每个元素的控制台日志放在帖子中。 – OiciTrap

回答

0

你想用ng-repeat="question_cluster in stored_questions_clusters | orderBy:'-position'"

这将降序排列

排序您question_clusters看看第一个例子上Angulars order by documentation