Obtain results from an array containing method objects

Currently, I am working on implementing a date range picker using Vue.js and have established an array of methods containing preset ranges.

presetRanges:{
  last7Days(){
    return{
      label: 'Last 7 days',
      dateRange:{
        start: this.$moment(today).substract(7, 'd')
      }
    }
  },
  last30Days(){
    return{
      label: 'Last 30 days',
      dateRange:{
        start: this.$moment(today).substract(30, 'd')
      }
    }
  },
  last60Days(){
    return{
      label: 'Last 60 days',
      dateRange:{
        start: this.$moment(today).substract(60, 'd')
      }
    }
  },
}

I am facing an issue with displaying each method's returned label in a for loop. The following code snippet was previously functional but seems to be causing problems now:

<li v-for="(item, idx) in presetRanges" :key="idx">"
  {{ item.label }} 
</li>

I attempted using {{ item().label }} as well, however, it also did not yield the desired output.

Answer №1

Your object's structure seems to be incorrect; the functions should be written as a: () => () within the object. The solution to your problem could look something like this on https://example.com/codepen

Answer №2

<ul v-for="group in selectedGroups">
  {{ group.name }} 
</ul>

Try implementing this solution for your particular scenario

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

Customize Button Colors in Bootstrap 4

I'm encountering difficulties when attempting to change the color of the buttons labeled "Print," "Excel," and "PDF". Despite referring to a guide, I wasn't able to succeed. The provided test case differs from my code but shares the same CSS and ...

Leveraging Next.js to efficiently handle multiple asynchronous requests with NextResponse

I have developed a login/signup application using NextJS. When attempting to log in, the logic in my route.ts file sends requests to a MongoDB database to check if the user exists and if the password is correct. However, instead of receiving the expected 4 ...

Animate out Material UI element with zoom effect and then remove it from the

I'm currently working on a dynamic user interface that allows for adding and removing items dynamically. Each item has both an add and remove button, with a special animation effect using Zoom. While this works smoothly when adding new items, I encoun ...

Ways to perform a redirect following data retrieval from a post request

I am working on a post method for a servlet, where the servlet returns a web page after forwarding a request to another page. Instead of directly redirecting using window.location = "/AnotherServlet", I have tried various solutions including passing parame ...

Bind the prototype to the JavaScript object

Consider this scenario where I have JSON data containing person objects. [ { "name": "Alice", "age": 28, }, { "name": "Bob", "age": 33 } ] Upon parsing, an array with two JavaScript objects is obtained. Suppose I want to add a ...

Tips for displaying a digital keyboard when a webpage loads on iOS Safari

While developing a website, I noticed that the virtual keyboard fails to appear when an input field gains focus during the page load process. As per Apple's policy restrictions, this functionality is not allowed. However, I am interested in finding a ...

What are the steps to switch the dropdown values?

I am facing an issue with swapping values in two dropdowns. The scenario is that I have a dropdown with minimal values and another one with maximum values. If a value selected in the first dropdown is greater than the value in the second dropdown, they nee ...

Could the inner object's value be retrieved from the wrapper object in a Vuex getter prior to mounting?

Currently grappling with a challenge while working on Vuex and VueJS involving the Computed property. To sum it up, I have a nested object within the Vuex state, attempting to retrieve a key from this inner object in a Vuex getter to display the value in ...

Unable to sort nested JSON data in ngTable

I have successfully built an angularjs application using ngTable, however, I am facing an issue with sorting. The JSON structure is nested but the values are appearing correctly in the table. If anyone has a solution to this problem, please let me know. ...

Angular Satellizer causing issues with Facebook login on mobile devices

Issue Currently, I'm developing an application using Angular and have successfully integrated Facebook login through Satellizer. The functionality works flawlessly on desktop browsers; however, when accessed from mobile devices, it tends to be unreli ...

Best practices for uploading an array of objects (multiple image files) using Node.js

Encountering an issue in my application where I need to upload multiple photos. The object consists of motherPhoto, fatherPhoto, spousePhoto, and siblingsPhoto: { "mothername": "kerin", "motherPhoto": "C:/fakepath/mot ...

How can data be transmitted to the client using node.js?

I'm curious about how to transfer data from a node.js server to a client. Here is an example of some node.js code - var http = require('http'); var data = "data to send to client"; var server = http.createServer(function (request, respon ...

Issue with background image resizing when touched on mobile Chrome due to background-size property set to cover

My current challenge involves setting a background image for a mobile page using a new image specifically designed for mobile devices. The image is set with the property background-size: cover, and it works perfectly on all platforms except for mobile Chro ...

Discovering a solution to extract a value from an Array of objects without explicitly referencing the key has proven to be quite challenging, as my extensive online research has failed to yield any similar or closely related problems

So I had this specific constant value const uniqueObjArr = [ { asdfgfjhjkl:"example 123" }, { qwertyuiop:"example 456" }, { zxcvbnmqwerty:"example 678" }, ] I aim to retrieve the ...

Struggling with developing a chrome extension

I have successfully developed a Chrome extension that, when clicked, says hello world. However, I am facing an issue with creating a simple button that triggers an alert when pressed. Could it be due to the inclusion of JavaScript in an HTML extension file ...

"The Material UI date picker is encountering an issue with the error prop, which is being evaluated

I have developed a date picker that utilizes the Jalali calendar. While attempting to pass error checking using the error prop in the following code: <LocalizationProvider dateAdapter={AdapterJalali}> <MobileDatePicker label={lab ...

Importing .js files from the static folder in Nuxt.js: a step-by-step guide

I'm in the process of transitioning my website, which is currently built using html/css/js, to Nuxt.js so that I can automatically update it from an API. To maintain the same website structure, I have broken down my code into components and imported ...

What is the process of using TypeScript to import a constant exported in JavaScript?

In the environment I'm using typescript 2.6.1. Within react-table's index.js file, there is a declaration that looks like this: import defaultProps from './defaultProps' import propTypes from './propTypes' export const React ...

Transferring data between different elements in a React application

I am currently learning React and facing some challenges in terms of passing data between components. Even after reviewing various tutorials and blogs, I am still struggling to make things work. Within my project, I have two child components named Body-c ...

Tips for toggling the visibility of a <div> element with a click event, even when there is already a click event assigned

No matter what I try, nothing seems to be working for me. I'm looking to hide the <div id="disqus_thread"> at first and then reveal it when I click on the link "commenting", after the comments have loaded. This particular link is located at the ...