我正在编写一个有菜单的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},
];
...
结果以这种方式呈现:Tre
,Due
,Home
,而不是按位置Home
,Due
,Tre
呈现。
我该如何解决这个问题?
答案 0 :(得分:1)
只需使用documentation中描述的reverse
:
<ul class="nav navbar-nav" ng-repeat="menuItem in menu | orderBy:'position':reverse">