How to run JavaScript code within a Vue template without triggering a render

Currently, I am attempting to run code inside the <script> tag.

In my setup, there are two arrays: one for the dataset and another for the structure of the repeater. The schema within each object contains a 'value' property, which serves as the default value if the dataset object does not have any value.

schema:[
  { type: 'text', name:'name', value:'John'},
  { type: 'number', name:'age', value:'0' }
]

dataset: [
  { name: 'Peter', age: 18 },
  { name: 'Luca' },
  { name: 'Anna', age: 25 }
]

I am working on creating a repeater that includes inputs and populates the data with values from the dataset.

The following code section is functioning properly, but I will explain my current issue afterward.

<template>
    <div class="repeater-container">
        <div class="repeater-wrapper">
            <div 
                class="repeater-item"
                v-for="(repeaterData, i) in dataset"
            >
                <template
                    v-for="(input, y) in schema"
                    :key="name+(i+1)+'_instance'+(y+1)"
                >
                    {{ (dataset[i][input.name]) ? input.value = dataset[i][input.name] : '' }}

                    <Input
                        :input="input"
                    />
                </template>
                
            </div>
        </div>
    </div>
</template>

I have implemented a loop that ensures the repeater renders the same number of items as the dataset contains. Within this loop, there is an inner loop that displays each input defined in the schema.

My goal is to extract the dataset value and use the default value if no value is present.

Although everything seems to be functioning correctly, the line: {{ (dataset[i][input.name]) ? input.value = dataset[i][input.name] : '' }} actually displays the result rather than executing silently in the background. Is there a way to achieve this without printing out the result of the ternary condition?

The Input Component belongs to me and functions properly. Omitting it here to avoid unnecessary complexity in the explanation.

Thank you for taking the time to read through this question :)

Answer №1

One approach could be to create a computed property named processedItems which can preprocess the data and include a displayValue property for each item. I encountered a similar issue recently.

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

angularFire encounters difficulties when attempting to add information to Firebase

I am currently utilizing angularFire and attempting to save form data to firebase using $add. Any assistance on this matter would be highly appreciated. All the console logs are showing correctly, as I am able to view the data in the console. Apologies for ...

Tips for eliminating default classes from Mui Typography styling

I’ve been working on creating a Typography element and noticed some default MUI CSS classes added when debugging in the browser. I attempted to disable them by using empty arrays at the end of the sx prop, but it did not work as expected. In the image p ...

What is the proper way to remove items in complex relationship scenarios?

Exploring the concept of creating a school survey system with customizable surveys, featuring sections that can be added to specific surveys. These sections house questions related to various topics, such as the campus environment. An issue arises when at ...

What is the best lifecycle hook to use for initializing components?

Below is an example where I am using the created lifecycle method to subscribe to the event service. Is this a common practice? Are there better or more appropriate ways or lifecycle methods to achieve the same functionality? const ViewComponent = { d ...

Expressions involving arrays in JavaScript

While diving into Eloquent JS, I stumbled upon this code snippet that left me puzzled. The explanation given didn't quite click with me, so I'm reaching out for some clarification on why the second console.log returns the value it does. Take a l ...

Having trouble with table sorting in Jquery?

I am a beginner in the realm of Jquery and web programming. Recently, I attempted to implement the tablesorter jquery plugin for one of my projects but encountered issues with making it work properly. In search of a solution, I turned to Stack Overflow. C ...

Uncovering the Telltale Signs of a Modified Ext.FormPanel

How can I enable the "Save" button in my Ext.FormPanel only when a user modifies values within the form? What is the best method to detect changes made by the user? I attempted using form.on("change") and SelectionMode but encountered no success. ...

Vue Navigation Guard automatically redirects users when trying to access a URL directly

I'm currently setting up Vue Navigation Guards. A guard I have in place redirects users from the Index component to the Dashboard component if they are authenticated with Firebase Auth. The redirect works perfectly when navigating to the Index page t ...

Utilizing Webpack in conjunction with Vue JS 2.6 and the latest VueCLI 4.0

Currently, I am in the process of setting up Webpack using VueCli 4.0. In the past, when using the deprecated version of Vue Cli, running the command vue init webpack my-project would generate a project that was ready for webpack, babel, SASS, linting, ro ...

Creating dynamic animations in React/Redux that respond to user actions

As I near the completion of my first React+Redux application, I am eager to incorporate animations throughout the different sections of the project. However, I have found that the existing solutions do not quite meet my expectations. The ReactCSSTransition ...

Declaration of variables in Node.js

Just getting started with Nodejs and JavaScript. I've kicked off a project using express generator and have mongoose package installed as well. In my routes/index.js file, here is the code snippet: var express = require('express'); var r ...

Error encountered in NextJS: Trying to call res.unstable_revalidate which is not a function

I recently tried out a cutting-edge feature introduced in NextJS v.12.1 . The API itself is functioning correctly and can be accessed. However, I encountered a 500 error with the message res.unstable_revalidate is not a function. This issue persisted wheth ...

How to utilize the ternary operator efficiently to evaluate multiple conditions in React

Is there a way to change the style based on the route using react router? I want the description route to display in orange when the user is in the description route, white when in the teacher-add-course route, and green for all other routes. However, th ...

Iterate through JSON data and access values based on keys using a $.each loop

I have retrieved JSON data from the controller using AJAX and now I want to access this data. The data is in the form of a list of objects (array) with key-value pairs, so I am planning to use .each() function to go through all the data. The array looks li ...

In search of a resolution for the error message "multipart: NextPart: bufio: buffer full" while attempting to upload an image via a fetch post request. Can anyone provide guidance

What steps can be taken to resolve the issue "multipart: NextPart: bufio: buffer full" when using a fetch post request to upload an image? I have a feature on my website that allows users to upload profile pictures. I use a fetch post request for this pur ...

Encountering an error while utilizing the Tether JavaScript Library

I'm currently in the process of developing a new website and I'd like to add a footer within a container div situated at the bottom. After some research, I came across a JavaScript library known as Tether (), but I've run into issues with i ...

Using socket.io in a Django template without the need for the node.js service or socket.io.js file

I am working on a Django app that requires real-time push to clients. I have decided to use node.js and socket.io as it is considered the easiest platform for achieving this functionality. To implement this, I have included the socket.io framework code in ...

Firefox experiencing issues with the onchange event

Here in this block of code, I have two dropdown lists: one for department and the other for section name. Based on the selected department, I dynamically change the options available for the section name dropdown list and then populate the values from both ...

A guide to displaying SVG graphics in a Jupyter notebook with the help of jsdom, D3, and IJavascript

Although I'm not an expert in frontend development, I have been experimenting with Javascript and D3 lately. As someone who typically works on scientific analysis in Python using Jupyter Notebooks, I thought it would be interesting to apply a similar ...

Acquiring JSON-formatted data through the oracledb npm package in conjunction with Node.js

I am currently working with oracledb npm to request data in JSON format and here is the select block example I am using: const block = 'BEGIN ' + ':response := PK.getData(:param);' + 'END;'; The block is ...