I have a project using VueJs and I am looking to extract JavaScript variables to create hidden fields.
My goal is to set the name of the field based on the index of the variable, following a zig-zag naming schema.
For example:
<input type="text" name="segment[{index}][field_name]" :value="{value}">
The JavaScript Variable:
var test_template = {
0: {
nb: 2
},
1: {
nb: 1
},
2: {
nb: 4
}
};
Foreach Loop for Generating Hidden Fields with Variables :
<div v-for="(a,index) in test_template" class="row">
<input type="hidden" :name="segment[index][nb]" :value="a.nb">
</div>
In this code snippet, :name dynamically accesses VueJS values. index is a VueJS variable, but "segment" is not - it's actually a string.
However, I need this structure to generate an array of inputs.
Is there a way to achieve this?
Or are there any alternative solutions available?
Thank you in advance!