js根据对象数组中的时间来排序

  dataList:[
    {
        id:"1,
        name:"li",
       addtime:'2019-02-06 :08:30'
    }
  ]
   
 computed: {
      newdataList: function() {
        return this.sortKey(this.dataList, "addtime");
      }
    },

 sortKey(array, key) {
        return array.sort(function(a, b) {
          var x = a[key];
          var y = b[key];
          return x > y ? -1 : x < y ? 1 : 0;
        });
      },

猜你喜欢

转载自www.cnblogs.com/huanhuan55/p/11134110.html
今日推荐