jQuery+ajax读取json数据并按照价格排序示例


Posted in jQuery onMarch 28, 2018

本文实例讲述了jQuery+ajax读取json数据并按照价格排序。分享给大家供大家参考,具体如下:

<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title></title>
 <script src="jquery-1.9.1.js"></script>
 <script>
 $.ajax({
  url: 'data.json',//获取本地json数据,在同文件夹下
  type: "get",
  success: function(resp) {
  console.log(resp); //原始数据
  var data = resp;
  //原生javascript sort() 方法
  data.data.sort(function(good1, good2) {
   /* 用价格排序由小到大 */
   return good1.price1 > good2.price1;
  });
  console.log(data.data);//排序后的数据
  },
  error: function(resp) {
  alert("系统繁忙,请稍后再试...");
  }
 });
 </script>
</head>
<body>
</body>
</html>

json数据 data.json:

{
 "code": 0,
 "data": [{
  "id": 16,
  "title": "fiveplus棉质纯色拼接圆领连衣裙",
  "name": "FivePlus2017新品女夏装棉质纯色拼接圆领短袖连衣裙2JM2080240",
  "promotion": "促销活动",
  "size": "XXl;Xl;M;S;L",
  "color": "深蓝;深绿",
  "picMini": "",
  "pic": "/upload/20170826161653_20170823141557.jpg,/upload/20170826161653_20170823141625.jpg,/upload/20170826161653_20170823141803.jpg,/upload/20170826161653_20170823141857.jpg,/upload/20170826161653_20170823141925.jpg",
  "parameter": "材质成分:棉68%聚酯纤维29.5%聚氨酯弹性纤维(氨纶)2.5%;销售渠道类型:商场同款(线上线下都销售);货号:2JM2080240;裙长:短裙;品牌:FivePlus;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:深蓝650米白010;尺码:X、S、M、L",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 399.00,
  "price2": 799.00,
  "longPic": "/upload/20170828102154_haibao (1).png",
  "score": 20,
  "createDate": "2017-08-26 14:49:09",
  "updateDate": "2017-08-26 14:49:09"
 }, {
  "id": 18,
  "title": "MOCO高腰拼接无袖镂空蕾丝连衣裙",
  "name": "MOCO高腰拼接无袖镂空蕾丝连衣裙修身A字裙子MA162SKT106摩安珂",
  "promotion": null,
  "size": "S;M",
  "color": "白色;黑色",
  "picMini": "",
  "pic": "/upload/20170826161938_TB1BiAdOFXXXXaYXXXXXXXXXXXX_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170826161938_TB2PwEAa30kpuFjSspdXXX4YXXa_!!1746622942.jpg_430x430q90.jpg,/upload/20170826161938_TB2uqPaaStkpuFjy0FhXXXQzFXa_!!1746622942.jpg_430x430q90.jpg,/upload/20170826161938_TB2ZW4HcR0kpuFjSsziXXa.oVXa_!!1746622942.jpg_430x430q90.jpg,/upload/20170826161938_TB22u2TaC0mpuFjSZPiXXbssVXa_!!1746622942.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:聚酯纤维94.4%聚氨酯弹性纤维(氨纶)5.6%;销售渠道类型:商场同款(线上线下都销售);货号:MA162SKT106;风格:街头;街头:欧美组合;形式:单件;裙长:短裙;款式:其他/other;袖长:无袖;领型:圆领;袖型:常规;腰型:高腰衣;门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:镂空勾花镂空蕾丝;品牌:Mo&Co./摩安珂;适用年龄:25-29周岁;年份季节:2016年夏季",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 300.00,
  "price2": 400.00,
  "longPic": null,
  "score": 20,
  "createDate": "2017-08-26 15:10:48",
  "updateDate": "2017-08-26 15:10:48"
 }, {
  "id": 20,
  "title": "CMissSixty夏装拼接露肩式牛仔连衣裙",
  "name": "CMissSixty夏装拼接露肩式牛仔连衣裙套装662DJ3220000",
  "promotion": null,
  "size": "XSML",
  "color": "深蓝;红色;白色",
  "picMini": "",
  "pic": "/upload/20170826162219_TB1F80hQXXXXXc8XXXXXXXXXXXX_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170826162219_TB2jpAydDcCL1FjSZFPXXXZgpXa_!!1880906465.jpg_430x430q90.jpg,/upload/20170826162219_TB2NnpRi5pnpuFjSZFkXXc4ZpXa_!!1880906465.jpg_430x430q90.jpg,/upload/20170826162219_TB2UB4Wi98mpuFjSZFMXXaxpVXa_!!1880906465.jpg_430x430q90.jpg,/upload/20170826162219_TB2zhxMi.hnpuFjSZFEXXX0PFXa_!!1880906465.jpg_430x430q90.jpg",
  "parameter": "材质成分:棉98.4%聚氨酯弹性纤维(氨纶)1.6%;销售渠道类型:商场同款(线上线下都销售);货号:662DJ3220000;裙长:中裙;品牌:Misssixty;适用年龄:25-29周岁;年份季节:2016年夏季;颜色分类:深蓝F58;尺码:XS、S、M、L",
  "businessName": "测试111",
  "typeName": "连衣裙",
  "businessId": 3,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 800.00,
  "price2": 1000.00,
  "longPic": "",
  "score": 30,
  "createDate": "2017-08-26 16:21:49",
  "updateDate": "2017-08-26 16:21:49"
 }, {
  "id": 45,
  "title": "雪纺连衣裙2017新款秋装七分袖气质时尚女装碎花修身连衣裙春秋",
  "name": "气质女神,春秋必备",
  "promotion": null,
  "size": "SMLXL",
  "color": "白色;粉色;兰色;黑色",
  "picMini": "",
  "pic": "/upload/20170828111058_TB1vZ7MQFXXXXaLXVXXXXXXXXXX_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111058_TB2Dtj2hw0kpuFjSspdXXX4YXXa_!!729863055.jpg_430x430q90.jpg,/upload/20170828111058_TB2off_hB0kpuFjSsziXXa.oVXa_!!729863055.jpg_430x430q90.jpg,/upload/20170828111058_TB2pOW1hylnpuFjSZFgXXbi7FXa_!!729863055.jpg_430x430q90.jpg,/upload/20170828111058_TB2SRuLgmxjpuFjSszeXXaeMVXa_!!729863055.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:AF5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:S、M、L、XL",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 139.00,
  "price2": 259.00,
  "longPic": "",
  "score": 13,
  "createDate": "2017-08-28 11:10:41",
  "updateDate": "2017-08-28 11:10:41"
 }, {
  "id": 46,
  "title": "韩版女装2017夏季新款冰丝针织小黑裙连衣裙中裙女夏装露肩a字裙",
  "name": "新款冰丝针织小黑裙",
  "promotion": null,
  "size": "SMLXL",
  "color": "黑色",
  "picMini": "",
  "pic": "/upload/20170828111250_TB1pFJsPFXXXXbUXVXXXXXXXXXX_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111250_TB2aHefXxRDOuFjSZFzXXcIipXa_!!2923124116.jpg_430x430q90.jpg,/upload/20170828111250_TB2CBbAeB0kpuFjSsziXXa.oVXa_!!2923124116.jpg_430x430q90.jpg,/upload/20170828111250_TB2wbcahCJjpuFjy0FdXXXmoFXa_!!2923124116.jpg_430x430q90.jpg,/upload/20170828111250_TB21GzPeB8lpuFjSspaXXXJKpXa_!!2923124116.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:AF5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:S、M、L、XL",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 158.00,
  "price2": 188.00,
  "longPic": "",
  "score": 15,
  "createDate": "2017-08-28 11:15:09",
  "updateDate": "2017-08-28 11:15:09"
 }, {
  "id": 47,
  "title": "吊带露背沙滩裙女夏2017新款海边度假性感波西米亚长裙显瘦连衣裙",
  "name": "吊带露背沙滩裙",
  "promotion": null,
  "size": "LSM",
  "color": "094花俏",
  "picMini": "",
  "pic": "/upload/20170828111644_TB1CbX8RVXXXXaqXVXXXXXXXXXX_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111644_TB2e5Yfp0RopuFjSZFtXXcanpXa_!!1969979810.jpg_430x430q90.jpg,/upload/20170828111644_TB2Q0ZZvNXkpuFjy0FiXXbUfFXa_!!1969979810.jpg_430x430q90.jpg,/upload/20170828111644_TB2qXsqvSBjpuFjSsplXXa5MVXa_!!1969979810.jpg_430x430q90.jpg,/upload/20170828111644_TB2twgOkutTMeFjSZFOXXaTiVXa_!!1969979810.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:AF5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:S、M、L、XL",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 148.00,
  "price2": 248.00,
  "longPic": "",
  "score": 14,
  "createDate": "2017-08-28 11:17:44",
  "updateDate": "2017-08-28 11:17:44"
 }, {
  "id": 49,
  "title": "Palglg裙子女2017新款夏季女装韩版宽松挂脖a字网纱连衣裙3353",
  "name": "精致绣花宽松显瘦减龄蝴蝶结系带",
  "promotion": null,
  "size": "SML",
  "color": "藕粉色;白色;浅绿色",
  "picMini": "",
  "pic": "/upload/20170828111920_TB1HTyLX0.LL1JjSZFEXXcVmXXa_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828111920_TB2BAcZubVkpuFjSspcXXbSMVXa_!!2456840063.jpg_430x430q90.jpg,/upload/20170828111920_TB2cnK7gH0kpuFjy0FjXXcBbVXa_!!2456840063.jpg_430x430q90.jpg,/upload/20170828111920_TB2rm4utMxlpuFjy0FoXXa.lXXa_!!2456840063.jpg_430x430q90.jpg,/upload/20170828111920_TB2xLw0hYxmpuFjSZJiXXXauVXa_!!2456840063.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:AF5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:S、M、L、XL",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 169.00,
  "price2": 369.00,
  "longPic": "",
  "score": 16,
  "createDate": "2017-08-28 11:20:06",
  "updateDate": "2017-08-28 11:20:06"
 }, {
  "id": 50,
  "title": "拉夏贝尔2017夏季新款bf风韩版气质潮裙子学生衬衫式连衣裙衣女",
  "name": "bf风韩版气质潮裙子",
  "promotion": null,
  "size": "SML",
  "color": "粉红;白色;浅蓝",
  "picMini": "",
  "pic": "/upload/20170828112125_TB1J2CUXo4WMKJjSspmXXcznpXa_!!0-item_pic.jpg_430x430q90.jpg,/upload/20170828112125_TB2K_FOiYXlpuFjSszfXXcSGXXa_!!2146742267.jpg_430x430q90.jpg,/upload/20170828112125_TB2nL6ht3JkpuFjSszcXXXfsFXa_!!2146742267.jpg_430x430q90.jpg,/upload/20170828112125_TB2Skz0dlU4h1JjSZFLXXaFMpXa_!!2146742267.jpg_430x430q90.jpg,/upload/20170828112125_TB2WEVJi9hlpuFjSspkXXa1ApXa_!!2146742267.jpg_430x430q90.jpg",
  "parameter": "廓形:A型;材质成分:其他100%;销售渠道类型:纯电商(只在线上销售);货号:AF5130;风格:通勤;通勤:韩版组合形式:单件;裙长:中裙;款式:其他/other;袖长:七分袖;领型:圆领;袖型:常规;腰型:中腰;衣门襟:拉链;裙型:A字裙;图案:花色;流行元素/工艺:绣花拼接螺纹拉链;品牌:芳香之城;面料:雪纺;适用年龄:25-29周岁;年份季节:2017年夏季;颜色分类:白色、粉色、兰色、黑色;尺码:S、M、L、XL",
  "businessName": "北京房益宝",
  "typeName": "连衣裙",
  "businessId": 1,
  "status": 1,
  "typeId": 8,
  "brandId": null,
  "price1": 199.00,
  "price2": 399.00,
  "longPic": "",
  "score": 19,
  "createDate": "2017-08-28 11:21:49",
  "updateDate": "2017-08-28 11:21:49"
 }
 ]
}
jQuery 相关文章推荐
jquery插件制作 自增长输入框实现代码
Aug 17 jQuery
jQuery动态追加页面数据以及事件委托详解
May 06 jQuery
jQuery扇形定时器插件pietimer使用方法详解
Jul 18 jQuery
简单实现jQuery轮播效果
Aug 18 jQuery
jQuery实现用户信息表格的添加和删除功能
Sep 12 jQuery
jQuery实现的粘性滚动导航栏效果实例【附源码下载】
Oct 19 jQuery
JS和JQuery实现雪花飘落效果
Nov 30 jQuery
jquery 给动态生成的标签绑定事件的几种方法总结
Feb 24 jQuery
jQuery使用动画队列自定义动画操作示例
Jun 16 jQuery
jQuery实现轮播图及其原理详解
Apr 12 jQuery
JQuery常用简单动画操作方法回顾与总结
Dec 07 jQuery
jQuery实现带进度条的轮播图
Sep 13 jQuery
基于jQuery实现Ajax验证用户名是否可用实例
Mar 25 #jQuery
jQuery实现的回车触发按钮事件功能示例
Mar 25 #jQuery
jQuery+Cookie实现切换皮肤功能【附源码下载】
Mar 25 #jQuery
jQuery实现新闻播报滚动及淡入淡出效果示例
Mar 23 #jQuery
jquery的 filter()方法使用教程
Mar 22 #jQuery
浅谈jquery fullpage 插件增加头部和版权的方法
Mar 20 #jQuery
jQuery替换节点元素的操作方法
Mar 18 #jQuery
You might like
PHP配置文件中最常用四个ini函数
2007/03/19 PHP
php中突破基于HTTP_REFERER的防盗链措施(stream_context_create)
2011/03/29 PHP
关于IIS php调用com组件的权限问题
2012/01/11 PHP
ThinkPHP实现非标准名称数据表快速创建模型的方法
2014/11/29 PHP
基于PHP代码实现中奖概率算法可用于刮刮卡、大转盘等抽奖算法
2015/12/20 PHP
PHP进程通信基础之信号
2017/02/19 PHP
php处理抢购类功能的高并发请求
2018/02/08 PHP
js实现简单div拖拽功能实例
2015/05/12 Javascript
PHP+jQuery+Ajax+Mysql如何实现发表心情功能
2015/08/06 Javascript
JS组件Bootstrap导航条使用方法详解
2016/04/29 Javascript
BootStrap中的表单大全
2016/09/07 Javascript
AngularJS bootstrap启动详解及实例代码
2016/09/14 Javascript
require.js 加载 vue组件 r.js 合并压缩的实例
2016/10/14 Javascript
小程序开发实战:实现九宫格界面的导航的代码实现
2017/01/19 Javascript
在vue中读取本地Json文件的方法
2018/09/06 Javascript
JavaScript学习教程之cookie与webstorage
2019/06/23 Javascript
Node.js实现简单的爬取的示例代码
2019/06/25 Javascript
JavaScript随机数的组合问题案例分析
2020/05/16 Javascript
详解为什么Vue中的v-if和v-for不建议一起用
2021/01/13 Vue.js
[02:12]2015国际邀请赛 SHOWOPEN
2015/08/05 DOTA
PYTHON正则表达式 re模块使用说明
2011/05/19 Python
python文件和目录操作函数小结
2014/07/11 Python
python实现统计代码行数的方法
2015/05/22 Python
Python3下错误AttributeError: ‘dict’ object has no attribute’iteritems‘的分析与解决
2017/07/06 Python
TensorFlow平台下Python实现神经网络
2018/03/10 Python
Python拼接字符串的7种方法总结
2018/11/01 Python
Python爬虫之UserAgent的使用实例
2019/02/21 Python
python浪漫表白源码
2019/04/05 Python
Pytorch中index_select() 函数的实现理解
2019/11/19 Python
纽约的奢华内衣店:Journelle
2016/07/29 全球购物
巴西最大的运动品牌:Olympikus
2020/07/14 全球购物
体育教师求职信
2014/06/30 职场文书
公司收款委托书范本
2014/09/20 职场文书
质量主管工作职责
2014/09/26 职场文书
2015年乡镇党务公开工作总结
2015/05/19 职场文书
Java实现经典游戏泡泡堂的示例代码
2022/04/04 Java/Android