dynamic rendering from REST call

This commit is contained in:
gaz8860 Gary 2023-04-13 21:04:18 +01:00
parent 9d20919f2c
commit 539221c456
3 changed files with 10 additions and 8 deletions

View File

@ -1,12 +1,11 @@
public class Component {
public int Type {get; set;}
public string Text {get; set;}
public List<Stats> Chart {get; set;}
public Component(int type, string text="", List<Stats> chart = null){
public Component(int type, string text){
Type = type;
Text = text;
Chart = chart;
}
}

View File

@ -0,0 +1,3 @@
public class Schema {
public Component[] components {get; set;}
}

View File

@ -14,16 +14,16 @@
break;
}
}
}
@code {
public List<Component> data;
private Component[] data;
protected override async Task OnInitializedAsync()
{
var response = await httpClient.GetAsync("http://localhost:8080");
var json = await response.Content.ReadAsStringAsync();
data = JsonSerializer.Deserialize<List<Component>>(json);
var response = await httpClient.GetStringAsync("http://localhost:8080/schema");
var options = new JsonSerializerOptions {PropertyNameCaseInsensitive = true};
var json = JsonSerializer.Deserialize<Schema>(response, options);
data = json.components;
}
}