Explaining this concept can be a bit complex. I am tasked with creating an object that contains properties from dynamic HTML code. To illustrate, let's use an example:
Firstly, here is my data object:
var myObject = {Field1: 'Value1', Field2: 'Value2'};
Next, I have an array listing the properties of my object like so:
var myArray = ['Field1', 'Field2'];
I then utilize this array to generate <input>
elements in a for loop:
<div v-for="property in myArray">
<input type="text" :value="myObject[property]" />
</div>
The challenge at hand is retrieving the values from these dynamically generated inputs, either as an object or an array.
While it may seem straightforward to just grab myObject
, the issue arises when the input values change (since they are user-modifiable). We also want to avoid directly binding the inputs to myObject
, as we need myObject
to stay in its original state even if the input values are altered.
My question is, how can I create a new object and bind my inputs to that newly created object?