【发布时间】:2019-01-22 08:25:42
【问题描述】:
我有一个 json 文件中的数据列表。我想显示所有月份,但我希望匹配的年份只显示为重要的一年。 我以不同的名称发布了这个问题,因为没有人看到它。 看图片: 该图像显示了相同的数据,但它被分成了年和月。我不想一遍又一遍地重复 2017 这个词,我希望它只是在粉红色块的中间说 2017。问题是它需要与数据相对应,因为数据一直在变化,它说 2017 年很容易变成 2018 年,所以它需要说出数据指定的正确年份。
JSON:
[
{
"month": "2017-03-01",
"modelVolume" [{
"id": 1,
"model": P213
}]
}
{
"month": "2017-03-01",
"modelVolume" [{
"id": 1,
"model": P213
}]
}
{
"month": "2017-03-01",
"modelVolume" [{
"id": 1,
"model": P213
}]
}
{
"month": "2017-03-01",
"modelVolume" [{
"id": 1,
"model": P213
}]
}
{
"month": "2017-03-01",
"modelVolume" [{
"id": 1,
"model": P213
}]
}
{
"month": "2017-03-01",
"modelVolume" [{
"id": 1,
"model": P213
}]
}
{
"month": "2017-03-01",
"modelVolume" [{
"id": 1,
"model": P213
}]
}
{
"month": "2017-03-01",
"modelVolume" [{
"id": 1,
"model": P213
}]
}
{
"month": "2017-03-01",
"modelVolume" [{
"id": 1,
"model": P213
}]
}]
我只使用“月”数据来解决这个问题。
HTML:年份:
<div class="row justify-content-md-center">
<div class="col-md-auto">
<table id="year">
<tr>
<th class="y17" class="y18" *ngFor="let value of groupVolumes(groupKeys()[0])" [ngClass]="getYear(value.month)">{{ value.month | date: "yyyy" | uppercase }}</th>
</tr>
</table>
</div>
</div>
月份:
<div class="row justify-content-md-center">
<div class="col-md-auto" class="scroll">
<table id ="t2">
<tr>
<th class="line">Line 1</th>
<th class="y18" *ngFor="let value of groupVolumes(groupKeys()[0])" [ngClass]="getYear(value.month)">{{ value.month | date: "MMM" | uppercase }}</th>
</tr>
【问题讨论】:
-
而不是做一个 ngFor,为什么不为那个 groupkeys 集合的长度做一个 colspan 你应该结合类属性 - 你不应该有 2
标签: html json angular data-manipulation