Incorporating a "for" loop similar to this in VueJS code entails writing it in the following manner: `for(let i = 0; i < x; i

I'm working on creating a for loop in vue.js that looks like this:

<div class="row" v-for="i = 0; i < numberOfRanking; i++">
   <div class="col s6 m6 l6">
     Rank 1
   </div>
   <div class="col s6 m6 l6">
     <input type="text" name="reward-sph-rank-1">
   </div>
</div>

My goal is to create dynamic fields where users can select the ranking they want to add. How should I go about achieving this?

Answer №1

To display a range of values, you can use the v-for directive with an integer value:

new Vue({
  el: '#app',
  data() {
    return {
      numberOfRanking: 4,
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.1/vue.min.js"></script>
<div id="app">
  <div class="row" v-for="i in numberOfRanking">
    <div class="col s6 m6 l6">
      Rank {{ i }}
    </div>
    <div class="col s6 m6 l6">
      <input type="text" :name="'reward-sph-rank-' + i">
    </div>
  </div>
</div>

Read more about using v-for in the official documentation.

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

AutomatedPostBack wipes out the data stored in my dropdownlist variable

While using javascript and asp.net, I have encountered an issue with the AutoPostBack function clearing a variable called 'callBackReason' that I declared in Javascript from a dropdownlist. Unfortunately, I need to keep this variable in Javascrip ...

Graph fails to load upon initial page load

I am currently experiencing an issue with angular-charts in my application. Initially, I created a line chart that displayed perfectly. However, when I added a second chart (pie), the first chart stopped showing on the front end unless I hovered over it or ...

Filtering an object based on keys within an ng-repeat loop

I need help with displaying only the items listed in defaults and excluding the others. <ul ng-controller="Ctrl" class="dropdown-menu"> <li ng-repeat="(key, value) in Employee.KeyValue | filter:DefaultKeys(key) ">{{key}}</li> </ul ...

.js script not being rendered within the ng-view

I am facing an issue with my index.html file which contains ng-view. I have included the necessary .js files in the index.html, but these scripts are not being applied to the injected view. index.html <!DOCTYPE html> <html class="no-js css-menub ...

What could be the reason for XMLHttpRequest's readystate being something other than 4?

Currently delving into the realm of AJAX for the first time, and endeavoring to construct a basic application that computes the required grade on a final exam based on past assessment results. The user keys in their grades into the form, subsequent to whi ...

Is there a way to implement tab functionality in jQuery UI through an onclick event?

My goal is to enhance an existing jQuery UI Tab container by adding tab information and then updating the contents through re-initialization. To see a demonstration of what I am trying to achieve, take a look at this JSFiddle: http://jsfiddle.net/dmchale9 ...

File declaring Vue3 Typescript types

I'm working with a Vue3 plugin in JavaScript, here's a snippet of the code: const myPlugin = { install(Vue, config) { // do something } export default myPlugin; This code is located in index.js and will be called by app.use. F ...

Converting a stringArray into a collection of function pointers for a librarySystem: A step-by

Right now, I am in the process of creating a library system In the code snippet below, there is a stringArray ['greet','name'] used as dependencies. The goal is to convert this stringArray into an array of functions and pass it into gr ...

What is the proper way for the curry function to function effectively?

Here's a function that I came across: function curry(fn) { var args = [].slice.call(arguments, 1); return function() { return fn.call(this, args.concat([].slice.call(arguments))); }; } I always thought this was the correct way fo ...

Transforming a Multi-Dimensional Array into an HTML Table

Experimenting with a new idea. I hope the solution is straightforward; I just can't seem to figure it out. Imagine I have an array like this: var items = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]; My goal is to rearrange the data so that it looks like t ...

Distinguishing Between Jquery Event Binding Methods

Can you explain the distinction between the two statements below and recommend which one to use in a given scenario? $(document).on("click","#btn",callback); $("#btn").on("click",callback); ...

Merging two distinct arrays of objects in JavaScript can be achieved by utilizing various methods and

I have a challenge where I need to merge two arrays of objects in a nested way. var array1=[{ PersonalID: '11', qusetionNumber: '1', value: 'Something' }, { PersonalID: '12', qusetionNumber: '2& ...

What are the steps to input information from an API into a chart?

Utilizing vue-chart.js in conjunction with Vue2, I encounter an issue when trying to pass API data to a chart. My approach involves using the Vuex store to fetch data from the API. However, the example provided on vue-chartjs.org for handling APIs is lacki ...

Having issues with my jQuery getJSON request. It's returning an empty response even though

I have been struggling to find a solution to this particular issue with no luck... Here is the jQuery getJSON request that I am working on: $.getJSON("http://localhost:8080/context/json/removeEntity.html", { contentId : 1, entIndex : entityIndex ...

Eliminate file extensions from a URL within an IIS server

Seeking advice on how to create a consistent layout for my web pages that doesn't display the .cshtml tag in the URL. I am using JQuery, JavaScript, HTML, CSS, ASP.net (Web Pages Logic). Example URL: http:// www.site.com/page.htm New to ASP and stil ...

Using the .splice() method in Javascript to eliminate elements from an array

I am currently working on a function that loops through an array and eliminates any elements that are false, null, 0, undefined, NaN, or an empty string. Instead of returning an empty array as expected, the current output is [null,0,null,null,""]. Below i ...

Is there a way to automatically focus on a newly created element using JavaScript?

Whenever a user presses the enter key in a single input field, it will become disabled and a new one will appear. I am looking to automatically focus on the newly created input field each time, while also removing the default blue border that appears when ...

Can the pointerover event be managed on a container within the am5 library?

While attempting to add an HTML label to a map and trigger a pointerover event, I encountered issues. The objective was to change the HTML content upon hover. Despite trying to incorporate a tooltip, the hover event failed to work properly, and the tooltip ...

Utilizing Datatables for efficient time filtering with the help of moment.js

Currently, my setup includes datatables v1.10.11 and Jquery v 2.2.0. Everything is functioning as intended, but I am interested in adding an additional date filter to my existing datepicker. The goal is to filter items that are older than 3 years from to ...

assigning the browser's width to a variable within an scss file

Is there a way to dynamically set the browser's width as a variable? I am familiar with @media queries, but I need to calculate the browser's width for a specific purpose. I attempted using jQuery to achieve this, and it works well with a fixed ...