当前位置:网站首页>js_array object is changed to be sorted (including parallel sorting)
js_array object is changed to be sorted (including parallel sorting)
2022-08-06 02:32:00 【The breeze is not the moon】
需求:按照total分数排名,如果分数(total)一样,to rank in a tie(sort).
The original data structure is as follows:
The format of the received data is as follows:
一 : es6 写法
data() {
return {
datas: [],
};
},
methods: {
rank(itemE) {
return this.datas.filter(item => {
let totalA = item.total;
let totalB = itemE.total;
return totalA > totalB;
}).length + 1
},
// Request interface to process data
getSort() {
let _this = this
this.datas= res.data// Data from the background request interfaceres.data
this.datas.forEach(item => {
item.sort = _this.rank(item);
})
console.log(this.datas)
},
}
二 : jQuery写法
methods: {
rank(itemE) {
return $.grep(listVM.datas, function (item, index) {
let totalA = item.total;
let totalB = itemE.total;
return totalA > totalB;
}).length + 1;
},
// Request interface to process data
getSort() {
listVM.datas = res.data;// Data from the background request interfaceres.data
$.each(listVM.datas, function (index, item) {
item.rankTotal = listVM.rank(item);
});
}
}
边栏推荐
- C. Robot in a Hallway Educational Codeforces Round 133 (Rated for Div. 2)dp
- ftp 报错 227 Entering Passive Mode (192,168,169,141,213,232)
- linux下mysql cpu占用过高问题查找思路
- MySQL high-performance construction 1: Centos7+Mysql7.5 builds master-slave replication
- 图解 JVM 内存结构
- Seata Failed to get available servers: endpoint format should like ip:port 报错原因/解决方案汇总版(看完本文必解决问题)
- 详解AUTOSAR:AUTOSRA软件架构(理论篇—2)
- 网址收藏-技术类
- How did Soul, who submitted a prospectus to the Hong Kong Stock Exchange, capture the hearts of thousands of Generation Z with the social metaverse?
- 在线问题反馈模块实战(二十):实现文件批量导出到zip压缩包中功能
猜你喜欢
随机推荐
codeforces 50A.Domino piling
eslint和prettier实现代码格式化
3个云渲染平台的价格体系,哪个最合适(四)
ansible copy 模块
ftp 报错 553 Could not create file
产业园区实现产业集聚的三大举措
Students' illegal use of the database causes the school's IP to be permanently blocked
Software Engineering - University Gymnasium Management System Class Diagram
codeforces 4A.watermelon
(shape pressure dp) shortest Hamilton path
九、MFC控件(一)
相机标定 >> 坐标系转换@内参、外参
MySQL -- 安装部署环境(一键安装脚本)
读书笔记 如何阅读一本书
Xpansiv acquires APX to expand environmental commodity market infrastructure
快速查看Oracle数据库告警日志的存储位置
用低代码如何搭建一套进销存管理系统(采购、销售、库存一体化管理)?
向港交所递交招股书的Soul,如何以社交元宇宙俘获万千Z世代的心?
ansible ping 模块
缓存算法有哪些分类呢?









