経緯
C#/Blazorを使ってJsっぽいことがしたい。
いやいや、Jsですればいいやんって?
そういう理不尽さが社会にはあるんや。
コード
以外と簡単やな。
<table class=@Table>
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table
@code{
private WeatherForecast? forecasts;
private string table = "";
public string Table { get; set; } = "table";
protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast>("WeatherForecast");
}
}
Js知らない人がC#でjsっぽいことができるぞーという歓喜と結局、jsのほうがドキュメントが多いから、jsでやろうってなって、中途半端になる落ちがあるかもしれない。
jsを解読してC#で記述していくという二度手間翻訳作業が起きないことを期待しているが、すでに頭の中ではjsのあれってどうやってやるんだろーっていう頭になっている。
js系列でやろうぜ。。