2017-11-25 118 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或僅與類嘗試?是的,我做過 –