I have this variable inside data():
JavaScript
x
24
24
1
jsonStatham: {
2
"uniqueOne": {
3
"field1": "",
4
"field2": "",
5
"field3": "",
6
"field4": "",
7
"field5": "",
8
"freeTextArea": ""
9
},
10
"uniqueTwo": {
11
"field1": "",
12
"field2": "",
13
"field3":"",
14
"field4":"",
15
"field5":"",
16
"freeTextArea":""
17
},
18
"uniqueThree": {
19
"field1": "",
20
"field2": "",
21
"freeTextArea": ""
22
}
23
},
24
What I want is to check if a value from this input field:
JavaScript
1
2
1
<input type="text" name="platform" placeholder="Platform" id="platform" v-model="platform" required/>
2
is matching one of the keys of “jsonStatham” (uniqueOne/Two/Three) and then push the keys of the matching key into an array. so if the input === uniqueOne, so this array:
JavaScript
1
4
1
inputFields: [
2
3
],
4
Will look like this: inputFields[“field1″,”field2″,”field3″,”field4″,”field5”]
That’s what I tried:
JavaScript
1
14
14
1
appendFields() {
2
3
for (const [key, value] of Object.entries(this.jsonStatham)) {
4
if(this.brand === this.jsonStatham[key]){
5
//console.log("Brand =>", this.brand)
6
}
7
//console.log(`${key}: ${value}`);
8
this.inputFields.push({
9
[key]:value
10
})
11
}
12
//console.log("ALL input Fields: n",this.inputFields)
13
},
14
What I get in inputFields is “uniqueOne”,”uniqueTwo”,”uniqueThree”
Advertisement
Answer
JavaScript
1
4
1
if (this.jsonStatham.hasOwnProperty(this.brand)) {
2
this.inputFields.push(Object.keys(this.jsonStatham[this.brand]));
3
}
4