search

Home  >  Q&A  >  body text

angular.js - 如何实现ng-repeat倒序循环?

我想要用angularjs循环一个json数组,

<p class="gwc-p mar-t20"  ng-repeat="shopdata in cartinfo.shopList" >
</p>

但是我想要倒叙的循环有什么方法吗?

仅有的幸福仅有的幸福2753 days ago883

reply all(3)I'll reply

  • 为情所困

    为情所困2017-05-15 17:01:17

    Try this:

    <p class="gwc-p mar-t20"  ng-repeat="shopdata in cartinfo.shopList.slice().reverse()" ></p>
    

    Or declare a filter...

    js:

    app.filter('reverse', function() {
        return function(items) {
            return items.slice().reverse();
        };
    });
    

    view:

    <p class="gwc-p mar-t20"  ng-repeat="shopdata in cartinfo.shopList | reverse" ></p>

    reply
    0
  • ringa_lee

    ringa_lee2017-05-15 17:01:17

    js itself has the reverse function reverse()

    reply
    0
  • 迷茫

    迷茫2017-05-15 17:01:17

    <p class="gwc-p mar-t20" ng-repeat="shopdata in cartinfo.shopList | orderBy:shopId:reverse"></p>

    reply
    0
  • Cancelreply