2017-11-25 116 views
0

我想根据他们的ID来订购一些锂。如何使用AngularJS更改列表项目的顺序?

目前我有:

<ul bx-slider="" id="rotator" style="width: auto; position: relative;"> 

    <li class="promo-banner ng-scope" ng-repeat="feature in events | limitTo:2" 
      bx-slider-item="" ordering="" id="ORDER-ROTATOR2" 
      style="float: none; list-style: none; position: absolute; width: 1510px; z-index: 50; display: block;"> 
    </li> 

    <li class="promo-banner ng-scope" ng-repeat="feature in events | limitTo:2" 
     bx-slider-item="" id="ORDER-ROTATOR1" ordering="" 
     style="float: none; list-style: none; position: absolute; width: 1510px; z-index: 0; display: none;"> 
    </li> 

</ul> 

和我的指令是:

.directive('ordering', function() { 

    var linker2 = function (scope, element, attrs) { 

     var elem = angular.element('#rotator').find('li').sort(sortMe); 
     console.log(elem); 
     angular.element('#rotator').append(elem); 

     function sortMe(a, b) { 
      return a.id < b.id; 
     } 

    }; 

    return { 
     link: linker2 
    } 
}) 

它看起来像它的排序,但不是他们的ID。

任何想法?

+0

可以使用OrderBy管? – bryan60

+0

我可以使用orderby按className或id进行排序吗? –

+0

是的,它的文档是广泛的,它是原生的angularjs – bryan60

回答

0

您可以使用排序依据与angularjs

过滤器有多个参数,

<li class="promo-banner ng-scope" ng-repeat="feature in events | limitTo:2 | orderBy:['className','id']" bx-slider-item="" ordering="" id="ORDER-ROTATOR2" style="float: none; list-style: none; position: absolute; width: 1510px; z-index: 50; display: block;"></li> 
+0

它似乎并没有工作。还请注意,列表项是通过使用指令来获取其ID。也许orderBy出现时,李先生还没有得到它的ID? –

+0

你试过1吗? – Sajeetharan

+0

你的意思是,如果只用ID或仅与类尝试?是的,我做过 –