Working with checkboxes generated through v-for loop manipulation

Greetings everyone, this is my first time reaching out for help, so please bear with me.

I am encountering difficulties with vue-js specifically related to component manipulation. My issue lies in creating checkboxes from an array that consists of a String property and a boolean checked value.

Below is the array in question:

checkedRequests: [
    {
      property: 'cid',
      checked: true
    },
    {
      property: 'companyName',
      checked: true
    },
    {
      property: 'gln',
      checked: true
    },
    {
      property: 'address',
      checked: true
    },
]

Furthermore, here is the vue div code snippet:

<div class="checkDiv" v-for="item in checkedRequests" :key="item.property">
  <input type="checkbox" id="item.property" v-model="item.checked">
  <label for="item.property">{{ item.property }}</label>
  <br>
</div>

The problem I am facing occurs when attempting to check or uncheck the boxes. Only the first property ('cid') is being manipulated instead of the intended one. For example, if I click on 'address' to toggle its checked value to false, 'cid' will be affected instead. Although the data is displayed correctly, due to this error in the array structure, the checked boxes do not align accordingly.

Thank you for any assistance in advance!

Answer №1

At this moment, you are currently using id="item.property" and for="item.property" as a string. Switching to a binding of :id="item.property" and :for="item.property" should help resolve the issue you are facing

  <div class="checkDiv" v-for="item in checkedRequests" :key="item.property">
    <input type="checkbox" :id="item.property" v-model="item.checked" />
    <label :for="item.property">{{ item.property }}</label>
    <br />
  </div>

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

Modify form layout upon selection of a specific radio button

Hey there! I'm a student currently diving into the world of JavaScript, CSS, and HTML. However, I've encountered a little problem while working on an exercise that involves using Bootstrap. function ShowForm(formId){ document.getElementByI ...

Is there a way to dynamically create a property and assign a value to it on the fly?

When retrieving data from my API, I receive two arrays - one comprising column names and the other containing corresponding data. In order to utilize ag-grid effectively, it is necessary to map these columns to properties of a class. For instance, if ther ...

The angular.copy() function cannot be used within angular brackets {{}}

Within my controller, I am utilizing the "as vm" syntax. To duplicate one data structure into a temporary one, I am employing angular.copy(). angular.copy(vm.data, vm.tempData = []) Yet, I have a desire to transfer this code to the template view so that ...

Is it possible to identify the origin URL of a user using Javascript or AngularJS?

Is it possible to use Angular to detect the origin URL of a user visiting my website in order to perform specific operations later on? ...

displaying a new image in a separate window while remaining in the current container

I am attempting to find a solution to create a page where the user can click on an image to open it while still keeping the other images available as options. I hope my explanation is clear enough for you to understand. The code might look something like ...

Cannon-js: Experience dynamic body bouncing on the y axis as it reacts to force applied on the x and z axes

Currently, I am working on an FPS game where the player controller applies force based on keyboard inputs to a dynamic cannon body. The angular dampening is set to 1 on the player body. The PlayerController class takes both the player class (which extends ...

JavaScript function to divide arrays into sequences

I have an array that looks like this: var arr = [12, 13, 14, 17, 18, 19, 20] I'm trying to figure out how to iterate through this array and split it into two arrays based on sequences. Essentially, if i+1 != true, I want to create a new array. var ...

The varying website layouts across different devices

I recently encountered an issue while working on my WordPress website. When I view the page, some features behave differently than expected. One example is a banner that moves in and out based on scroll position (using jQuery Waypoints). Interestingly, whe ...

Retrieve the undefined value of response.data from vuex, which was fetched using axios

When trying to retrieve response.data with console.log(this.$store.getters.getData) in a Vue component, it returns undefined. However, using console.log(resp.data) provides the desired response data. Even after attempting to access console.log(data) withi ...

This TypeScript error occurs when trying to assign a value of type 'null' to a parameter that expects a type of 'Error | PromiseLike<Error | undefined> | undefined'

Currently, I am making use of the Mobx Persist Store plugin which allows me to store MobX Store data locally. Although the documentation does not provide a TypeScript version, I made modifications to 2 lines of code (one in the readStore function and anot ...

Is a specific format necessary for express next(err) to function properly?

Recently, while working on my express sub app that utilizes the http-errors module, I encountered an interesting issue. When passing new Forbidden() to the next() callback, it seemed to vanish without triggering any callbacks. However, passing new Error() ...

Live Update Google Sheet Data to JSON Without Reloading Web Page

This particular function is executing smoothly. My main concern lies in updating a DOM element without reloading the webpage, if any alterations are made to the data on a Google sheet I am utilizing a JSON file from Google sheets: https://spreadsheets.g ...

Development of client and server using socket.io in node.js

I am trying to set up a basic demo using socket.io from http://socket.io The server (app.js) is functioning properly. However, I am encountering issues with the client side: <script src="/socket.io/socket.io.js"></script> <script ...

Having trouble setting cookies with Node.js Express?

Check out this code snippet: const app = express(); const cookieParser = require('cookie-parser'); app.use(cookieParser()); app.post("/pinfo", (req, res) => { var form = new formidable.IncomingForm(); form.parse(req, async functi ...

Countdown Widget - Transform "0 Days" to "Today" with jQuery

I am currently working on a countdown page using the Keith Woods Countdown jQuery plugin which can be found at . Here is the code I have implemented so far: $(document).ready(function () { var segera = new Date(); segera = new Date(segera.getFullYear(), 2 ...

Using the JavaScript moment library, you can easily convert a value into seconds

Could moment.js be used to format var timeValue = '65' into 01:05? While easier to format as ('HH:MM:SS'), passing a variable as 65 and converting it into ('mm:ss') results in '01:00' instead of '01:05'. C ...

What is the best way to utilize $.ajax for downloading JSON data from an HTML

I am currently facing an issue with a script that utilizes AJAX to retrieve JSON data. $.ajax({ type: "GET", url: url, /*url = index.html or data.json, many page use 1 script*/ success ...

Create a visual representation after inserting

I have created an input feature that allows me to paste images by using CTRL-V. The process involves copying an image from the browser and pasting it into the input field using CTRL-V. The result is an image in base64 format. Is there a way to manipulate ...

Could anyone provide some insight into the reason behind this occurrence?

I just came across the most peculiar situation I've ever experienced. Check out this unique test page: <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title></title> <script language=javascript> fun ...

Locate a specific element within an array and retrieve its corresponding index

Need help updating a boolean property for all objects in an array with the same user ID. I've outlined my MVC framework below in a concise manner. Model: var posts = [{id:1, user_id:1, is_following:true}, {id:2, user_id:1, is_cool:true}, ...