Answer the question
In order to leave comments, you need to log in
How to solve the problem of iterating over keys in objects?
I'll try to break it down for better understanding.
All work happens in Vue.js Inside the data object is 1 parameter object. Inside parameter there are 3 objects (tables) - netProfit, equityСapital, dividends. Inside each of these three objects are three keys - name, all, newValue. The value of the all key is an array with objects, each of which contains two keys - digit and customize. The digit contains data that will need to be displayed in the console. It is necessary to make it so that by clicking on any value in any of the 3 tables, this value is displayed in the console. Code below.
<div id="check-success">
<div class="main-wrap">
<div class="make-choice">
<h2>Выбор показателя</h2>
<ul v-for="(parameter, index) in parameters">
<li class="parameter-item">
<table class="parameter-table">
<tr class="table-row">
<td class="table-cell" @click="custValue(index)" v-for="(item, index) in parameter.all">
{{ item.digit }}
</td>
</tr>
</table>
</li>
</ul>
</div>
</div>
</div>
let checkSuccess = new Vue({
el: '#check-success',
data: {
parameters: {
netProfit: {
name: 'Чистая прибыль',
all: [{
digit: 240,
customize: false
}, {
digit: 2,
customize: false
}, {
digit: 3,
customize: false
}],
newValue: '',
},
equityСapital: {
name: 'Собственный капитал',
all: [{
digit: 250,
customize: false
}, {
digit: 300,
customize: false
}, {
digit: 6,
customize: false
}],
newValue: '',
},
dividends: {
name: 'Дивиденды',
all: [{
digit: 7,
customize: false
}, {
digit: 130,
customize: false
}, {
digit: 78,
customize: false
}],
newValue: '',
},
},
},
methods: {
custValue: function(index) {
let param = [this.parameters.netProfit, this.parameters.equityСapital, this.parameters.dividends];
for (let i = 0; i <= param.length; i++) {
console.log(param[index].all[index].digit);
}
},
},
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question