Blogger Information
Blog 67
fans 0
comment 2
visits 71968
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS时间相同的分组显示
搁浅
Original
417 people have browsed it

html

  1. //相同的时间只能显示一次
  2. <template v-for="(item,index) in arr">
  3. <div v-if="item.isTrue">{{ item }}</div>
  4. </template>

JS

  1. let arr = [
  2. {datetime:"2022-10-10 16:37:31"},
  3. {datetime:"2022-10-10 12:21:06"},
  4. {datetime:"2022-10-10 02:03:09"},
  5. {datetime:"2022-10-09 09:17:11"},
  6. {datetime:"2022-10-09 15:22:19"},
  7. {datetime:"2022-10-08 08:36:12"},
  8. ]
  9. // 获取年月日-时间数组
  10. const newArr = arr.map(item => item.datetime.split(" ")[0])
  11. // 对时间进行去重
  12. const arrSet = new Set(newArr)
  13. // 存放首次出现时间的下标数组
  14. let idList = []
  15. // 根据首次出现时间,将下标进行存储
  16. arrSet.forEach(val => {
  17. if (newArr.indexOf(val) != -1) {
  18. idList.push(newArr.indexOf(val))
  19. }
  20. })
  21. // 与原数组比较,若下标相同,则归为一组
  22. arr.forEach((val, idx) => {
  23. idList.forEach(val2 => {
  24. if (idx == val2) {
  25. //isTrue为分组标志,列表根据isTrue进行分组即可
  26. val.isTrue = true
  27. }
  28. })
  29. })
  30. //拆分时间和日期
  31. for (const key in arr) {
  32. arr[key].date = arr[key].datetime.split(" ")[0]
  33. arr[key].time = arr[key].datetime.split(" ")[1]
  34. }
  35. console.log(arr);
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post