Tips for showcasing all values in a nested array

In my Vue application, I am dealing with a nested array where users can select one date and multiple times which are saved as one object. The challenge I am facing now is how to display the selected date as a header (which works fine) and then list all the corresponding times for that date. Currently, I have only been able to display one time, but in cases where an object has multiple times, I am unable to display them all.

Is there anyone who could help me review my code?

Code snippet to display the contents of the array:

<v-card-text >
     <v-row>
      <v-col cols="4" v-for="(i, index) in datesFinal" >
        <h4>{{i.date}}</h4>
        <v-chip v-for="time in i.times">{{time.startTime + ":" + time.endTime}}</v-chip>
      </v-col>
     </v-row>
    </v-card-text>

Script tag:

<script>
import MeetingsTableComponent from "@/components/MeetingsTableComponent";
import DatePickerComponent from "@/components/DatePickerComponent";

export default {
  name: "NextMeetingCardComponent",

  data() {
    return {
      selectedTime: [],
      dates: new Date().toISOString().substr(0,10),
      datesFinal: [],
      dialog: false,
      menu: false,
      modal: false,
      menu2: false,
      menu3: false
    };
  },

  methods: {

    addTimeFields() {
      this.selectedTime.push({
        startTime: "",
        endTime: "",
      });
    },

    saveDateAndTIme(e) {
      this.datesFinal.push({
        date: this.dates,
        times: this.selectedTime
      });
      this.selectedTime = [];
    }
...

I believe my method is not working because I am trying to access [0], but this is just a guess on my part.

Answer №1

One possible solution to this problem is shown below:

<v-card-text>
    <v-row>
      <v-col cols="4" v-for="(item, index) in datesFinal" :key="index" >
        <h4>{{item.date}}</h4>
        <v-chip-group v-if="item.times.length !== 0">
          <v-chip v-for="(time, i) in item.times" :key="i">
            {{time.startTime + ":" + time.endTime}} 
          </v-chip>
        </v-chip-group>
        <v-chip-group v-else>
          <v-chip>no times </v-chip>
        </v-chip-group>
      </v-col>
    </v-row>
  </v-card-text>

Answer №2

Hmm, perhaps an alternative approach could be to utilize the Set method for filtering out duplicate dates. Subsequently, you can iterate through each item in this set to extract the corresponding times from the dataset.

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

Creating functions within the $scope that do not directly access the $scope object

tag, I am looking to create a $scope function that specifically manipulates the variables it receives. To test this functionality, I have set up a Plunker available at http://plnkr.co/edit/BCo9aH?p=preview. In my setup, there is an ng-repeat loop that lis ...

Issue encountered during Node.js installation

Every time I attempt to install node js, I encounter the following errors: C:\Users\Administrator>cd C:/xampp/htdocs/chat C:\xampp\htdocs\chat>npm install npm WARN package.json <a href="/cdn-cgi/l/email-protection" class ...

"Utilizing JSON parsing in Node.js and rendering the data in a Jade template

I need assistance with parsing JSON and presenting the response in a tabular format using Jade. Can you help me display the key-value pairs in two separate columns? Node.js exports.postMQinput = function(req, res) { req.assert('name', 'Q ...

Find the total number of records in fnClick: (datatables.net)

I am struggling with some code where I need to retrieve the total number of records. I posted about it on the datatables.net forum but unfortunately, no one was able to help me... tableTools: { "sSwfPath": window.STATIC_BASE + "scripts/datatable/s ...

Show the current phone number with the default flag instead of choosing the appropriate one using the initial country flag in intl-tel-input

Utilizing intl-tel-input to store a user's full international number in the database has been successful. However, when attempting to display the phone number, it correctly removes the country code but does not select the appropriate country flag; ins ...

Attempting to nest an AJAX request within the success callback of another AJAX request

I am attempting to execute two jQuery ajax calls, with the second call being made from the success callback of the first. I have experimented with different variations of the code, such as adjusting the brackets. Below is my attempted code snippet: $.aja ...

Can the server determine if a Parse user is currently logged in?

My current system allows users to log in or sign up client side, but I want to verify their login status from the server when they land on a page through a GET request. Is it feasible to do this? ...

At what point does a prop become officially designated as having the same value as what was initially passed to the component

I am experiencing unreliable behavior in my component, where a prop is passed and I need to debug it: <my-component :number="someNumber" /> The number prop is defined in my-component through a standard declaration: prop: ["number" ...

Are the Angular tests passing even before the asynchronous call has finished?

When running the following Angular (4) test for a service, it appears to pass before the Observable returns and hits the expect statement. it('should enter the assertion', inject( [ MockBackend, CellService ], ( backend: MockB ...

Pass a parameter to an AJAX request in order to retrieve data from a JSON file that is limited to a specific

I am working with a JSON file named example.json, structured as follows: { "User1": [{ "Age":21, "Dogs":5, "Cats":0 }], "User2": [{ "Age":19, "Dogs":2, "Cats":1 }] "User3 ...

Exploring the differences between using a local controller in Angular's MdDialog modal versus displaying a shadow at

I've been attempting to utilize an app-level controller to showcase a modal dialog. The local function controller tests are functioning flawlessly, but the app level controller is only showing a grey shadow instead of the expected dialog. The edit an ...

Verify if a certain value is present within a nested array

I need assistance with checking if a specific value is present within a nested array. Here is an example of the data I am dealing with: [ { name: 'alice', occupation: ['Artist', 'Musician'], }, { ...

What is the best way to populate an array with JSON data using jQuery?

As a newcomer to jQuery, I decided to experiment with the getJSON function. My goal was to extract the "id" section from a JSON file and store it in an array called planes using jQuery. This array would then be utilized in an autocomplete function to popul ...

Choose the radio button by clicking using jQuery

I am attempting to use jQuery to select a radio button on click. Despite multiple attempts, I have been unsuccessful so far. Here is my current code: JS $(document).ready(function() { $("#payment").click(function(event) { event.preventDefault() ...

Understanding the behavior of the enter key in Angular and Material forms

When creating forms in my MEAN application, I include the following code: <form novalidate [formGroup]="thesisForm" enctype="multipart/form-data" (keydown.enter)="$event.preventDefault()" (keydown.shift.enter)="$ev ...

Circular dependency in Typescript/Javascript: Attempting to extend a class with an undefined value will result in an error,

Query Greetings, encountering an issue with the code snippet below: TypeError: Super constructor null of SecondChild is not a constructor at new SecondChild (<anonymous>:8:19) at <anonymous>:49:13 at dn (<anonymous>:16:5449) ...

What is the best way to utilize the .done() callback in order to execute a function when new data is loaded upon request?

I have a web page that pulls data from a JSON feed, and there's also a button to load more content from the feed when clicked. I want to add additional elements inside the page for each item in the feed. I've managed to create a function that doe ...

Having trouble implementing express-unless to exclude specific routes from requiring authentication

Being relatively new to JavaScript and Node.js, I decided to incorporate express-jwt for authenticating most of my APIs. However, I wanted to exclude certain routes like /login and /register from authentication. After exploring the documentation for expr ...

Nested solution object populated with promises

Looking for a solution similar to the npm libraries p-props and p-all, but with the added functionality of recursively resolving promises. const values = { a: () => Promise.resolve(1), b: [() => Promise.resolve(2)], c: { d: () =&g ...

CdkVirtualFor does not display any content

I'm facing an issue with implementing cdk-virtual-scroll in my chat application. Unfortunately, it's not showing anything on the screen. Strangely, when I resort to using the regular "ngFor", everything works smoothly. However, as soon as I switc ...