我从 Vue.js 开始,我不知道如何计算 v-for 显示中的部分值和总值。
我从具有下一个结构的 JSON 中获取一些信息:
[saldos]
[bank]
[data]
[account]
- name
- balance
[account]
- name
- balance
[meta]
- info
[bank]
[data]
[account]
- name
- balance
[account]
- name
- balance
[meta]
- info
每个银行可以是 0 个账户、1 个账户或多个账户。
我需要获取每家银行的部分价值(它是同一家银行内所有账户“余额”的总和)和总值(它是之前为每家银行计算的所有部分价值的总和)
我的 Vue.js 文件是:
var saldo = new Vue({
el: "#listasaldos",
data: {
saldos:[],
},
created: function(){
console.log("Cargando ...");
this.get_saldos();
},
methods:{
get_saldos: function(){
fetch("./api.php?action=saldosapi")
.then(response=>response.json())
.then(json=>{this.saldos=json.saldos})
}
}
});
我的 HTML 文件是:
<div id="listasaldos">
<h1>Title</h1>
<h2>{{totalValue}}</h2>
<div v-for="bank in saldos">
<h3>{{partialValue}}</h3>
<table>
<thead>
<tr>
<th>Name</th>
<th>Balance</th>
</tr>
</thead>
<tbody v-for="account in bank.data">
<tr> {{account.name}}</tr>
<tr> {{account.balance}}</tr>
</tbody>
</table>
</div>
</div>
我该怎么做?
谢谢!