My API provides soccer game results in this format:
results:[
{
Group:"A"
Home: "Fc Barcelona",
Away: "Fc Porto"
Score: {
Home: 0,
Away: 0
},
{
Group:"A"
Home: "AC Milan",
Away: "Fc Barcelona"
Score: {
Home: 0,
Away: 1
},
{
Group:"A"
Home: "FC Barcelona",
Away: "AC Milan"
Score: {
Home: 2,
Away: 0
}
{
Group:"B"
Home: "Juventus",
Away: "Real Madrid"
Score: {
Home: 0,
Away: 1
}
]
However, I am facing issues with team duplicates and calculating points. I want to generate standings tables based on groups but can't sum up points of a team from multiple games using scores.
I have tried using if statements as shown in the code snippet provided, but it's not giving me the desired output. If you have a better solution, please share!
<tbody v-for="result in results" :key="result.index">
<div v-if="result.Group=='A'>
<tr>
<td>{{result.Home}}</td> <br> <-- need each team to be printed only once
<td>{{result.Score.Home}}</td> <-- logic needed to calculate and display points here based on score
</tr>
</div>
</tbody>
data () {
return {
results:[]
}
mounted () {
axios
.get('http://localhost/soccer/results',)
.then(response => (this.results = response.data))
}
The current output shows duplicated teams with their respective scores:
Team Score PTS
Fc Barcelona 0
Ac Milan 0
Fc Barcelona 2
However, my goal is to display teams along with their total points like this:
Team Score PTS
Fc Barcelona N/A 3
Ac Milan N/A 0