zoukankan      html  css  js  c++  java
  • js sort方法根据数组中对象的某一个属性值进行排序

            async getList() {
                await indexmodel.findAllSeller(this.queryInfo, data => {
                    console.log(data);
                    if (data.length <= 5) {
                        this.loadingType = 'noMore';
                    }
                    if (this.queryInfo.pageNo === 1) {
                        this.list = data;
                        this.list.sort(this.compare('distance'))
                    } else {
                        this.list = this.list.concat(data);
                        this.list.sort(this.compare('distance'))
                    }
                });
            },

        // 排序比较
            compare(property){
                 return function(a,b){
                        let value1 = a[property];
                        let value2 = b[property];
                        return value1 - value2;
                    }
            },
    console.log(this.list.sort(this.compare('distance')))

  • 相关阅读:
    struct pack unpack
    读书笔记 第四章&第五章
    The Sieve of Eratosthens(爱拉托逊斯筛选法)
    2013年3月百度之星A题
    2013年3月百度之星B题
    好句子
    BFS 与 DFS
    记录本
    HDU 2028 如何计算最小公倍数?
    HDU 2015 偶数求和 解题报告
  • 原文地址:https://www.cnblogs.com/2Octobering/p/13920360.html
Copyright © 2011-2022 走看看