在Lodash中,当我传递'desc'时,sortBy()无法按降序排序,当我调用函数时
const sortedData = _.sortBy(data, ['rawAvgPrice'], ['desc']);
。这对于升序排序可以正常工作,但对于降序排序不起作用。我已发布了我编写的排序功能。我阅读了“ lodash多列sortBy降序”线程,但它没有帮助我解决问题。因此决定发布这个问题。 /**
* @param {String} element - sorting object element name.
* @param {String} dir - the direction of the sort ASC/DESC.
* @param {Boolean} flag - Signaling to sort the table and update.
*/
sortTableNew(element, dir, flag) {
let direction = dir;
// Change the sorting from ASC to DESC/ DESC to ASC
if (flag) {
direction = dir === 'asc' ? 'desc' : 'asc';
}
// Getting the current open tabs details
const { activeTab } = this.$props.state.keywordSearch;
const { data } = this.$props.state.keywordSearch.tabs[activeTab];
const sortedData = _.sortBy(data, [element], [direction]);
// Updating the cache to dispatch data to the table
cachedHelper.updateCacheKeyword(cachedHelper.SCREEN_TYPE.keywordSearch, activeTab, sortedData);
cachedHelper.updateCacheSortType(cachedHelper.SCREEN_TYPE.keywordSearch, activeTab, direction, column);
},