【发布时间】:2019-08-01 19:25:05
【问题描述】:
所以我有一个 api 可以为我提供这样的足球比赛结果:
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
}
]
等等……
除此之外,我想根据组来整理排名表,但我有团队重复,我无法根据分数从多场比赛中总结出一个团队的积分
到目前为止,我已经尝试使用我提供的代码中的 if 语句来解决它,如果有更好的解决方案,请告诉我!
<tbody v-for="result in results" :key="result.index">
<div v-if="result.Group=='A'>
<tr>
<td>{{result.Home}}</td> <br> <-- i need teams to be print out once, not several times
<td>{{result.Score.Home}}</td> <-- i need this to be 'if result.Score.Home>0 add 3 points to the adequate team and print it out here'
</tr>
</div>
</tbody>
data () {
return {
results:[]
}
mounted () {
axios
.get('http://localhost/soccer/results',)
.then(response => (this.results = response.data))
}
使用示例中的代码,我将得到以下结果:
Team Score PTS
Fc Barcelona 0
Ac Milan 0
Fc Barcelona 2
我需要做到这一点(不需要Score,需要根据Score计算PTS,并且像这样只打印一次团队):
Team Score PTS
Fc Barcelona N/A 3
Ac Milan N/A 0
【问题讨论】:
-
不要尝试按原样使用您的数据。将其转换为可以在模板中直接使用的内容。
-
@RoyJ ,您好,感谢您的快速回答,您能给我一个简短的例子来说明如何实现这一点会很棒,谢谢
标签: javascript api vue.js ecmascript-6