dictArraySort (dictArray, sortKey, sortType="ascending", isTime = false) { if (!isTime) { if (sortType == 'ascending') { dictArray.sort(function (dictA, dictB) { return dictA[sortKey] - dictB[sortKey] }) } if (sortType == 'descending') { dictArray.sort(function (dictA, dictB) { return dictB[sortKey] - dictA[sortKey] }) } } else { // 如果是日期时间排序 if (sortType == 'ascending') { dictArray.sort(function (dictA, dictB) { return Date.parse(dictA[sortKey].replace(/-/g,"/"))-Date.parse(dictB[sortKey].replace(/-/g,"/")) }) } if (sortType == 'descending') { dictArray.sort(function (dictA, dictB) { return Date.parse(dictB[sortKey].replace(/-/g,"/"))-Date.parse(dictA[sortKey].replace(/-/g,"/")) }) } } return dictArray },
标签:return,dictArray,降序,sortKey,JS,dictA,dictB,升序,sortType From: https://www.cnblogs.com/rachelch/p/16825736.html