ng-repeat directive sort the data when using (key, value)

前端 未结 7 2139
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 09:40

I have a code something like this with ng-repeat = \"(key,value) in data\". In Controller:

  $scope.Dates = {\"Today\":\"30\",
                  \"This Wee         


        
7条回答
  •  爱一瞬间的悲伤
    2020-12-08 09:58

    There is actually an answer: it's called orderBy and not sort:

    https://docs.angularjs.org/api/ng/filter/orderBy

    {{ orderBy_expression | orderBy : expression : reverse}}

    
          {{friend.name}}
          {{friend.phone}}
          {{friend.age}}
        
    

    Your list just needs to be a list, and you might need an index to know set order

    $scope.Dates = [{index:1, "Today":"30"},
                      {index:2,"This Week":"42"},
                      {index:3,"This Month": "Oct"},
                      {index:4,"This Quarter" : "Bad"},
                      {index:5,"This Year" : 2013}]
    

    and then

    
              {{key}}
              {{value}}
             
    

提交回复
热议问题