博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何把后台返回数据的根据某个选项去重新排序?
阅读量:6257 次
发布时间:2019-06-22

本文共 5168 字,大约阅读时间需要 17 分钟。

比如:一个用户列表要按照用户的积分高低去排序渲染(一般后台会排序之后返回给你);

例如下面的data是请求回来的数据,

var data={      "ret_code": "0",      "ret_msg": "ok",      "data": {        "users": [              {            "pfid": 1000011,            "nickname": "cabbageancy",            "headimg": "http://wx.qlogo.cn/mmopen/ajNVdqHZLLASXYCVQQeiaXKA07Mx1Lu24juBVZ40ib9IsI6ImibfsWD1R3JS5I5L4LZMmgxpC4B7Y1taCZmXHQVKic4lbHibcntI7L6S7K4gnMW8/0",            "count": 0,            "follow_status": 0,            "score": 19,            "live_id":"454654646"          },          {            "pfid": 1000004,            "nickname": "减肥沟沟壑壑健健康康快快",            "headimg": "http://playback-langlive.ufile.ucloud.cn/4825891161c4d9a377be0785078c2158.jpg",            "count": 0,            "follow_status": 0,            "score": 17,            "live_id":"454654646"          },          {            "pfid": 1023841,            "nickname": "优雅的猫",            "headimg": "http://blob.ufile.ucloud.com.cn/e101f4896dbd4de38b7d7e7123828ee608d7b97251148720bb7678bf10ea21b8",            "count": 0,            "follow_status": null,            "score": 15,            "live_id":"454654646"          },          {            "pfid": 1000044,            "nickname": "嘻嘻哈哈??1213",            "headimg": "http://blob.ufile.ucloud.com.cn/45bd20f480c941f800a101bb484cb8be.jpg",            "count": 0,            "follow_status": null,            "score": 13,            "live_id":"454654646"          },          {            "pfid": 1000048,            "nickname": "珍珠奶茶?芋頭紅豆薏米",            "headimg": "http://blob.ufile.ucloud.com.cn/c8d240b8dfb870238431f43a392b312fba00a22c15230aa66f8e33cacc6debda",            "count": 0,            "follow_status": null,            "score": 10,            "live_id":"454654646"          },          {            "pfid": 1000830,            "nickname": "58665",            "headimg": "http://blob.ufile.ucloud.com.cn/a765a85a32fde0343476d3d5a54ce686d9370cd4e35f4ac941661c2ab6746bcd",            "count": 0,            "follow_status": null,            "score": 9,            "live_id":"454654646"          },          {            "pfid": 1000941,            "nickname": "随意",            "headimg": "http://playback-langlive.ufile.ucloud.cn/41395b6c4851bbc8d2ac49b643ea1420",            "count": 0,            "follow_status": 0,            "score": 8,            "live_id":"454654646"          },          {            "pfid": 1000052,            "nickname": "upper",            "headimg": "http://blob.ufile.ucloud.com.cn/9256deb2c705849daef63ace024d4fe121e68f712eefdc585692247a52cf1920",            "count": 0,            "follow_status": null,            "score": 7,            "live_id":"454654646"          },          {            "pfid": 1000733,            "nickname": "查房",            "headimg": "http://playback-langlive.ufile.ucloud.cn/8422f67af167df7d2b2caa78ac0a4773c4eade4575b343b5a82b7a48c4bf1427",            "count": 0,            "follow_status": null,            "score": 6,            "live_id":"454654646"          },          {            "pfid": 1000012,            "nickname": "c224002",            "headimg": "http://blob.ufile.ucloud.com.cn/0d94ae9dc33721c87af78a7b2099f5a7ab7395972444c7ab979e3dea46e8ba2e",            "count": 0,            "follow_status": null,            "score": 5,            "live_id":"454654646"          },          {            "pfid": 1000039,            "nickname": "哇呀唔唔無武呃呃?哇咔",            "headimg": "http://blob.ufile.ucloud.com.cn/25f0e2243ac9f515ed3be2fb1854c8b7db8e04b195a088962179cf5937ae25dd",            "count": 0,            "follow_status": null,            "score": 4,            "live_id":null          },          {            "pfid": 1000049,            "nickname": "思考解决",            "headimg": "http://blob.ufile.ucloud.com.cn/6b7f50b02ed10b72159ccf1f00a73ab9.jpg",            "count": 0,            "follow_status": null,            "score": 3,            "live_id":null          },          {            "pfid": 1000040,            "nickname": "?\"sting\"?",            "headimg": "http://blob.ufile.ucloud.com.cn/3f8f9f008d9d34a9b4cdffd32a06a3d8.jpg",            "count": 0,            "follow_status": null,            "score": 2,            "live_id":null          },          {            "pfid": 1000010,            "nickname": "gggggg",            "headimg": "http://blob.ufile.ucloud.com.cn/f9cb7d8ac961fb9b3d5a882aea55bfe5",            "count": 0,            "follow_status": null,            "score": 1,            "live_id":null          }        ],        "my": {          "live_id": null,          "live_key": "",          "stream_direction": 0,          "live_url": "",          "headimg": "http://blob.ufile.ucloud.com.cn/c8d240b8dfb870238431f43a392b312fba00a22c15230aa66f8e33cacc6debda",          "nickname": "珍珠奶茶?芋頭紅豆薏米",          "pfid": 1000048,          "follow_status": 0        }      }    }
var users=data.data.users;sortData(users);// 1 把人員按照積分从高到底排列,冒泡排序function sortData(lists){    for(var n=1;n
max){ var preData=lists[k]; lists[k]=lists[k+1]; lists[k+1]=preData; } } } console.log(lists);//此时lists就是按照积分高低排序之后的列表}

 

转载地址:http://fnxsa.baihongyu.com/

你可能感兴趣的文章
MQ产品比较-ActiveMQ-RocketMQ
查看>>
暂时没有想好呢。
查看>>
windows服务 MVC之@Html.Raw()用法 文件流的读写 简单工厂和工厂模式对比
查看>>
PHP解析URL并得到URL中的参数
查看>>
【vue.js】绑定click事件
查看>>
字体属性
查看>>
linux的iptables和firewall的区别
查看>>
Install RabbitMQ server in CentOS 7
查看>>
Eureka的优势
查看>>
Android项目实战(一): SpannableString与SpannableStringBuilder
查看>>
idea中的language level 介绍
查看>>
CTSC 2018酱油记
查看>>
php框架排名(Laravel一直第一)
查看>>
行贿罪、受贿罪刑事辩护6大要点
查看>>
java日期格式(年月日时分秒毫秒)
查看>>
看懂UML类图
查看>>
c#串口编程(转)
查看>>
OpenMVG学习笔记
查看>>
Ubuntu下 fatal error: Python.h: No such file or directory 解决方法
查看>>
微信小程序 (node) warning: possible EventEmitter memory leak detected
查看>>