【发布时间】:2021-12-11 16:12:16
【问题描述】:
我需要从 stockcomponents 获取计数 我的父组件使用子组件。对于此代码,计数为 0,但实际上数据更多
<Heading Size="HeadingSize.Is4">Count @ItemCount Entries</Heading>
<StockComponent @ref=stockComponent />
StockComponent stockComponent;
int ItemCount ;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(firstRender)
{
ItemCount = stockComponent.Count();
StateHasChanged();
}
}
** 我的 StockComponent **
private int count;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if(firstRender)
{
Items = await db.Item.ToListAsync();
count = Items.Count;
StateHasChanged();
}
}
public int Count ()
{
return count;
}
【问题讨论】:
标签: asp.net-mvc asp.net-core blazor