Including a heading if one has not already been established

Looking for a way to display date headlines in a list without duplicating them when multiple dates are the same.

For example, currently:

01.02.2019
- XY
05.03.2019
- ABC
05.03.2019
- DEF
05.03.2019
- FOO

Desired output:

01.02.2019
- XY
05.03.2019
- ABC
- DEF
- FOO

Here's the code snippet I'm using to check if the date is today:

HTML:
<template v-for="(meetup, index) in filteredItems">
    <v-subheader v-if="checkIsToday(meetup.date)" inset>
        <span v-if="todaySubheader === false">TODAY</span>
    </v-subheader>

Javascript:

data() {
        return {
            todaySubheader: false,
            [...]
            checkIsToday(val) {
                if (val && this.todaySubheader === false) {
                    this.todaySubheader = true
                }
                return isToday(new Date(val))
            },

Any suggestions on preventing the addition of a second headline after one has already been set?

(Using VueJS with Vuetify framework)

Answer №1

Your code snippet is missing the full context, making it difficult to understand how your Objects are structured.

A potential solution could involve utilizing a Vue Computed function to group items by date.

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
  }, {});

const items = [
  { name: 'XY', date: '01.02.2019' },
  { name: 'DEF', date: '05.03.2019' },
  { name: 'ABC', date: '05.03.2019' },
  { name: 'FOO', date: '05.03.2019' }
];

const groupByDate = groupBy('date');

console.log(
  JSON.stringify(groupByDate(items), null, 2)
);

Consider implementing this code within a computed Vue Function: Vue computed documentation

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubles encountered during the installation of Visual Web Developer 2010?

Here is the situation I'm facing: After encountering some issues with PHP while working on an ASP.net project, I decided to reinstall everything. The installation of Apache, MySQL, and PHP went smoothly, but now I seem to be facing some problems. I ...

The Ionic framework lacks support for the firebase and auth properties found in Firebase

Currently, I am developing a user-generated content feature along with buttons using ionic 5 and integrating it with the firebase app. I have been studying posts to incorporate them into my application. I am utilizing: "firebase": "^8.1.1&q ...

Refresh the DIV content using an external file

I have an external file containing text that is updated regularly. <div id='1'>TEST 1</div> <div id='2'>TEST 2</div> <div id='3'>TEST 3</div> This file is named IO.HTML. My script retrieves ...

Learn how to showcase a modal pop-up in AngularJS by utilizing the ng-if directive

Hello, I am new to working with AngularJS. My question is how can I display a modal pop-up box when the ng-if statement evaluates to false? Can you please provide guidance on how to solve this issue? Here is an example of the code snippet in HTML: <di ...

What could be causing my dropdown links to malfunction on the desktop version?

I've been developing a responsive website and encountering an issue. In desktop view, the icon on the far right (known as "dropdown-btn") is supposed to activate a dropdown menu with contact links. However, for some unknown reason, the links are not f ...

Simulated asynchronous operation in Pinia

I am currently working on a straightforward component that activates an async Pinia-action (when a button is clicked) and then executes a router.push(). However, I am facing some difficulties when trying to unit test this particular behavior. Specifically ...

Approximately 20% of spoken words are not accurately conveyed by Speech Synthesis Google Voices, failing to adhere to the intended voice selection

When using speechSynthesis.speak(utterance) in Chrome with the "Google UK English Female" voice, there is an issue where a male voice is randomly spoken instead. Any thoughts on how to resolve this? Latest Update: July 26th, 2022 This appears to be a bug ...

A guide on implementing nested view objects in ui-router for angular applications

Unfortunately, I am not well-versed in Angular. My objective is to display multiple views on a user profile page using ui-router. These are my current routes: (function() { 'use strict'; angular .module('app.routes') .config(r ...

Utilizing shared code amongst React components

There are several components with methods similar to the ones below: class Header extends Component { sidebarToggle(e) { e.preventDefault(); document.body.classList.toggle('sidebar-hidden'); } sidebarMinimize(e) { e.preventDe ...

Guide to integrating a custom-designed email subscription form into a Node JS application

I've recently kicked off a project to build a basic web app using the following tools: Vue.js Carbon Design System My next objective is to integrate a mailing list. I aim to incorporate a simple form with two main components: a text box and a subscr ...

Initiate node.js execution upon system boot

Just diving into node.js. In the process of setting up integration tests for a node.js app using mocha, I found this helpful guide: Here's how I created a server: var http = require('http'); this.server = http.createServer(function (req, ...

npm ERROR! The module './access-error.js' could not be located

I keep encountering an issue with NPM where I always get the error message npm ERR! Cannot find module './access-error.js'. Can anyone provide assistance? The problem initially arose when attempting to install vue-chartjs. Following the document ...

Guide on incorporating dynamic markers into MapBox using Vue/Nuxt

After setting up my MapBox, I wanted to dynamically add markers using Vue/Nuxt. However, the markers are not appearing on the map and I'm unsure of what the issue could be. The code snippet below shows that console.log() prints the correct coordinate ...

What are some effective ways to utilize customvalidator for performing clientside validation on two input fields?

I attempted to implement a asp:CustomValidator along with client-side JavaScript in order to validate that the user does not input the same new password as the old password using the following code... <script type="text/javascript"> function ...

Implementing JavaScript SDK to modify a Parse object upon a button click: A Step-by-Step Guide

Incorporating Parse.com and JavaScript SDK is the focal point here. The goal of the function below is: a) To provide a list of users that the current user must respond to regarding a friend request. b) When the "cancel" option is clicked, the state of th ...

Guide on parsing a JavaScript file and converting the default export module to JSON with Node.js

What I'm trying to accomplish in my Node.js project is reading a sample.js file with ES Module syntax and extracting the default export from it. sample.js import foo from "foo"; const bar = [ { name: "Homer", }, { n ...

Fetching server-side JavaScript source from a relative path within an ASP file

My setup involves a local IIS server pointing to a virtual workspace at c:\projects Within my c:\projects directory, I have the following folder structure: Game src asp test.asp jquery jquery.min.js The test ...

Having trouble converting a string to an array in JS? Splitting doesn't seem to be doing

I encountered an issue where I am reading data from a CSV file, storing the innerHTML to a variable (named content), which the browser recognizes as a string. However, when attempting to convert it to an array, I am facing difficulties. I attempted to use ...

Update all other input fields whenever a single field is modified. Implement using AngularJS (Link to Plunker included)

Check out this plunker example at http://plnkr.co/edit/Ll09uMtJEC0HqyGBRPj?p=preview Within the plunker, there are input fields for date, user, and car. It is possible to select values for all three fields. If I attempt to change the date, I would like ...

How to customize nouislider appearance using Bootstrap styles

I've been attempting to style the noUi tooltips to match the bootstrap design, but I've been unsuccessful so far. I'm wondering if there's an easy way to achieve this. I tried to structure the markup based on the bootstrap template ava ...