【发布时间】:2020-03-31 18:56:54
【问题描述】:
我正在尝试根据内容更改卡片的背景颜色,但它跳过了第一张卡片/div。设置背景颜色时如何防止第一张卡片被跳过? Blazor Fiddle
@foreach (TimeLog time in timeList)
{
<div class="largeCard" id="cardstyle" style="background-color: @cardColour ">
<div>
@if (time.LogType == "Work") cardColour = "#06065c";
else cardColour = "#5c0606";
<h6>@time.LogType</h6>
</div>
</div>
}
@code {
List<TimeLog> timeList = new List<TimeLog>();
TimeLog times = new TimeLog();
string cardColour;
public class TimeLog
{
public string LogType { get; set; }
}
protected override async Task OnInitializedAsync()
{
times = new TimeLog();
times.LogType = "Work";
timeList.Add(times);
times = new TimeLog();
times.LogType = "Vacation";
timeList.Add(times);
times = new TimeLog();
times.LogType = "Work";
timeList.Add(times);
times = new TimeLog();
times.LogType = "Work";
timeList.Add(times);
times = new TimeLog();
times.LogType = "Vacation";
timeList.Add(times);
times = new TimeLog();
times.LogType = "Work";
timeList.Add(times);
}
}
【问题讨论】:
标签: c# html css blazor blazor-server-side