Ensure that any nested object has a value of true, and then change it to false when clicked in a Vue application

I have a button on my template that, when clicked, should check all isActive values.

If any value is found to be true, it should be changed to false.

This is how my Vue script is structured:

data: function() {
  return {
    rates: {
       a: {
           x: [40, 60],
           isActive: false
       },
       b: {
           x: [66, 76],
           isActive: false
       },
       c: {
           x: [76, 108],
           isActive: false
       }
    }
  }
},
methods: {
  changeToFalse() {
     // This method will handle the changes
  }
}

And this is what my template code looks like:

<template>
  <div>
    <button @onclick="changeToFalse()"> Click Me </button>
  </div>
</template>

Note: All functionality, including the looping through and changing of values, should be contained within the changeToFalse() method. Thank you! :)

Answer №1

If you want to deactivate all active rates in your code, simply include the following code snippet within your method():

deactivateAllRates() {
     // This method deactivates all active rates
       for(let rate in this.prices) {
          if(this.prices[rate].isActive == true) {
                this.prices[rate].isActive = false;
             }
         console.log(this.prices[rate].isActive);
     }
  }

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

How can I prevent buttons from being created using ngFor in Angular?

I need help with creating an HTML table that includes a cell with a button and a dropdown generated using ngFor. How can I disable the buttons (generated via ngFor) if no value is selected from the dropdown? Here's what I have tried so far: In my App ...

Show the tooltip above the cursor if there is enough space in the viewport; otherwise, position it

I'm encountering an issue with positioning a tooltip that I'm creating. The tooltip's CSS is set to position: absolute, and I've implemented a mouse event handler that adjusts its top and left based on the pageX and pageY. While I cou ...

suggestions for organizing data in an AJAX/jQuery page

Welcome to my JavaScript/Ajax webpage that also utilizes jQuery. I am facing a challenge with displaying a nested structure. Once a top level element is displayed, users should be able to click on it and reveal the levels below (which are dynamically gene ...

Locating the Smallest Value in an Array of Objects

Looking at an object with keys containing arrays of objects that each have a price value. The goal is to find and return the lowest price value. In this scenario, aiming to return the value 8. Wondering if using the reduce method would be the best approach ...

Removing unwanted users in a React application

Recently, I started working with React. There's a project where I need to filter users based on their upvotes, with the user having the most upvotes appearing at the top. However, I'm struggling to implement this feature properly. Additionally, w ...

Using JSON to populate an Interface Array

In my Angular project, I've defined the following interface: export interface FruitsType { id: String; name: String; selected : String; } And this is the JSON data: { [ {"id" :"f1", "name": "apple", "selected": "false"}, {"id" ...

Change ES6 JavaScript to ES5 standard

Is there a way to transform this code snippet from other questions into ES5 format? I am attempting to extract data from a JSON array. var match = function(query, input) { return input.filter(function(entry) { return Object.entries(query).every(fun ...

Selector that targets an attribute in the beginning of its value [name^=value]

When trying to match input fields by name, I encountered a challenge. The names consist of a base name plus square brackets, which the PHP interpreter converts into arrays. According to the jQuery API, the suggested selector is as follows: ":input[name^=f ...

Challenges with Javascript arrays

let dataArray = []; let id = 23; let num = 12; let dogTrialSet = 15; let catTrialSet = 23; encountering an issue here dataArray.push({id:{num:num, dogTrialSet:dogTrialSet, catTrialSet:catTrialSet}}); sending AJAX request to PHP [dataArray] => Array ...

What causes parent class to clear input?

I am attempting to toggle a class on a parent element (either a div or form). My CSS adjusts the visibility of certain form elements based on this parent class. However, when the class is changed on the div or form, all the inputs within the form are clea ...

Is it possible to integrate the DataTable plugin into a Laravel Vue.js project effectively?

Recently, I've decided to add Vue.js to my Laravel application to improve its functionality. I'm now looking to integrate jQuery DataTable to display the data. If anyone has any suggestions on how to achieve this, especially because I'm stil ...

Initiating the onclick event for Input/Form

<form method="POST" onsubmit="return false;"> ... <input type="submit" name="button" value="Login" onclick="require('file.js').submitForm(this.form);"> ... </form> Is there a way to trigger the onclick event of this INPUT eleme ...

Counting the number of PHP inputs in a field

Hello, I am using a PHP script from Steve Dawson's website. To display the output on my HTML page, I am utilizing this AJAX script: <script> $.ajax({ type:'GET', url:'http://www.solariserat.se/count.php', data: ...

"Organize JavaScript array elements into groups based on their content

I am struggling with how to group specific variables in JavaScript. Here is the scenario: I have an array that contains categories, ranging from A-Z but it can vary (such as Animals - dogs - cats - etc). In another array, I have data from an XML file wi ...

Choose to selectively turn off designated referenced JavaScript files on Firefox

Is it possible to deactivate certain JavaScript files individually on Firefox/Firebug? Maybe through the use of another extension? I am experiencing issues with drag and drop functionality due to conflicts between multiple static JavaScript files. I' ...

Simulate a new Date object in Deno for testing purposes

Has anyone successfully implemented something similar to jest.spyOn(global, 'Date').mockImplementation(() => now); in Deno? I've searched through the Deno documentation for mock functionality available at this link, as well as explored t ...

Recurring occurrences of Ajax ViewComponent being triggered

I have encountered a problem with an on-click Ajax event that is triggering a Controller action/ViewComponent multiple times. The issue arises when I utilize Ajax on a button click to call a Controller Action, which inserts data into the database and then ...

Verifying form input with jQuery's range validation

Is there a way to validate a field within a specific range? I have been using additional-methods for validation, but I am unsure of how to specify the range parameter in my HTML. For example: <input type="text" class="rangeField" rel="[10, 20]" /> ...

Creating a dynamic NxNxN matrix from a basic array in Vue.js

Consider an array: listItems = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ,13 ,14 ,15 ,16, 17, 18, 19, 20, 21, 22, 23]; I would like to transform it into a 3-dimensional Array((Matrix of ROW x COLUMN)x SET according to the number of instances. Here is an exa ...

Determine the distance needed to cover the full field of view (

Currently, I am attempting to determine the maximum distance that the camera can zoom in on a sphere while still keeping the entire sphere visible on the screen. var dist = diameter / (2 * Math.tan( camera.fov * (Math.PI/180) / 2 )); The issue is that z ...