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

前端 未结 7 2152
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  猫巷女王i
    2020-12-08 10:01

    Object.keys doesn't reserve the order - FYI https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

    // array like object with random key ordering

    var an_obj = { 100: 'a', 2: 'b', 7: 'c' };
    console.log(Object.keys(an_obj)); // console: ['2', '7', '100']
    

    I convert it into an array of object

    $scope.Dates = [
            { id: "Today",      value:"30" },
            { id: "This Week",  value:"42" },
            { id: "This Month", value: "Oct" },
            { id: "This Quarter", value : "Bad" },
            { id: "This Year",  value : 2013 }
        ];
    
    
  • {{date.id}} -> {{date.value}}
  • http://jsfiddle.net/2hqew68k/1/

提交回复
热议问题