博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数组过滤
阅读量:5951 次
发布时间:2019-06-19

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

var flag = false; function showArrylist (typeFlag){ var hisHtml = ""; var list = [{"currentTime":"2018-12-28","data":[{"date":"2018-12-28 09:42:14","dateStr":"2018-12-28","msg":"你的Uni给你带来了6点积分奖励","timeStr":"09:42:14","type":1},{"date":"2018-12-28 09:42:14","dateStr":"2018-12-28","msg":"你喂食了你的Uni120g甜甜圈","timeStr":"09:42:14","type":0},{"date":"2018-12-27 18:12:55","dateStr":"2018-12-27","msg":"你喂食了你的Uni40g甜甜圈","timeStr":"18:12:55","type":0},{"date":"2018-12-27 14:16:38","dateStr":"2018-12-27","msg":"你喂食了你的Uni11g甜甜圈","timeStr":"14:16:38","type":0},{"date":"2018-12-27 13:11:06","dateStr":"2018-12-27","msg":"你喂食了你的Uni23g甜甜圈","timeStr":"13:11:06","type":0},{"date":"2018-12-27 10:48:30","dateStr":"2018-12-27","msg":"你喂食了你的Uni12g甜甜圈","timeStr":"10:48:30","type":0},{"date":"2018-12-27 09:36:33","dateStr":"2018-12-27","msg":"你的Uni给你带来了17点积分奖励","timeStr":"09:36:33","type":1},{"date":"2018-12-27 09:36:33","dateStr":"2018-12-27","msg":"你喂食了你的Uni23g甜甜圈","timeStr":"09:36:33","type":0},{"date":"2018-12-27 07:20:55","dateStr":"2018-12-27","msg":"你喂食了你的Uni86g甜甜圈","timeStr":"07:20:55","type":0}],"code":0}] var newArr = []; var timeArr = []; $(".uniDateshow").html(days); list.forEach(function(item,index){ timeArr.push(item.dateStr) }); timeArr = timeArr.filter(function(item,index,self){ return self.indexOf(item) == index }); // console.log(timeArr.length); for(var i=0; i< timeArr.length; i++) { var newJson = list.filter(function (item, index, array) { return item.dateStr == timeArr[i]; }); newArr.push(newJson); };

if(list.length > 0){ for(var i = 0; i < newArr.length; i++){ var msg = ""; var otype = ""; for(var j=0; j<newArr[i].length; j++) { if(newArr[i][j]["type"] === 0){ otype = "喂养" }else if(newArr[i][j]["type"] === 1){ otype = "积分奖励" }else if(newArr[i][j]["type"] === 2){ otype = "特别奖励" } msg += '

'+ otype + '
' + newArr[i][j]["timeStr"] + '

'+ newArr[i][j]["msg"] + '

' };

hisHtml += '
' + newArr[i][0]["dateStr"]+'
' + msg +'
';};复制代码

}else{ if(list.length === 0 && !flag){ hisHtml = "

近期您还没有喂养过Uni

只展示最近2周喂养记录
" }else if(list.length === 0 && flag){ //
(".recordlistType").last().addClass("dropload-noData");  } }; if(typeFlag){​('document').append(hisHtml); }else{ $("document").html(hisHtml); }; }

转载于:https://juejin.im/post/5c258bdf6fb9a049d37f2aed

你可能感兴趣的文章
java ee 5周 ajax
查看>>
canvas和svg
查看>>
结对:复利美化版
查看>>
HDU_2689_Sort it
查看>>
urllib模块使用笔记
查看>>
mysql 连接慢的问题(超过了1秒)
查看>>
1297. [SCOI2009]迷路【矩阵乘法】
查看>>
Linux嵌入式GDB调试环境搭建
查看>>
安全性测试要点转摘
查看>>
java分析jvm常用指令
查看>>
【Linux】Linux 在线安装yum
查看>>
oracle 管理操作 (转)
查看>>
DEV 等待窗口
查看>>
实验03博客园总结
查看>>
laravel captcha 验证码制作
查看>>
VS2017发布微服务到docker
查看>>
lombok
查看>>
Dev-FAT-UAT-PRO
查看>>
Maven, IntellJ Idea 配置注意点
查看>>
Android开发学习总结(五)——Android应用目录结构分析(转)
查看>>