简体   繁体   中英

Sort list by property name AngularJS

I have a complex object that looks like:

   {
      'street35':[
          {'address154': 'name14'},
          {'address244': 'name2'}
      ],
      'street2':[
          {'address15': 'name1'},
          {'address234': 'name2'}
      ]
   }

I'm binding it to the html using the (value, key) in object attribute that angular.js provides. I want to order by the value in this case by the street name. Any suggestions?

You can try this code:

JS:

   $scope.streetsObject = {
      'street35':[
          {'address154': 'name14'},
          {'address244': 'name2'}
      ],
      'street2':[
          {'address15': 'name1'},
          {'address234': 'name2'}
      ]
   }

HTML:

<div ng-repeat="street in streetsObject | orderBy">
    <span ng-repeat"name in street">
    </span>
</div>

The code supposes that you are using angular 1.3.0+.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM