ng-repeat orderBy位置不起作用

时间:2015-11-29 17:26:04

标签: javascript angularjs

我正在编写一个有菜单的Angular App,我这样划分:

HTML:

<ul class="nav navbar-nav" ng-repeat="menuItem in menu |  orderBy:'position'">
    <!-- Home  Mega Menu -->
    <li class="mega-menu">
        <a href="index-corporate.html">{{menuItem.testo}}</a>
    </li>
    <!-- Shortcode Menu Ends -->
    <!-- Header Search -->
    <li class="hidden-767" ng-show="$last">
        <a href="#" class="header-search">
            <span>
                <i class="fa fa-search"></i>
            </span>
        </a>
    </li>
</ul>

JS:

...
$scope.menu = [
    {testo: 'Home', link: 'index.html', position: 1},
    {testo: 'Due', link: 'index.html', position: 2},
    {testo: 'Tre', link: 'index.html', position: 3},
];
...

结果以这种方式呈现:TreDueHome,而不是按位置HomeDueTre呈现。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

只需使用documentation中描述的reverse

 <ul class="nav navbar-nav" ng-repeat="menuItem in menu |  orderBy:'position':reverse">