我想按照microsoft documentation中的示例创建一个模板化的表组件.
在这里,我想向表中添加一个排序函数:
// This is a function in the code-behind of TableTemplate.razor
public void SortSourceList(/*some args*/)
{
// sort based on given args
}
问题如下.我希望这个功能可以从子元素们那里访问,例如TableHeader
个项目:
@page "/somepage
<TableTemplate Items="pets" Context="pet">
<TableHeader>
<th>
<button class="btn btn-outline-secondary mr-2"
@onclick=<!--call the sorting function from here-->>
</th>
</TableHeader>
<RowTemplate>
...
</RowTemplate>
</TableTemplate>
@code{ // page related code - don't want to handle anything concerning the table here }
我知道这可以通过将TableTemplate
的实例作为CascadingParameter
传递来实现,但是如何在一个普通的html项目中获得它,它不是razor组件?此外,我不一定要将TableTemplate
实例作为类属性添加到任何子组件中(据我所知,访问级联参数需要TableTemplate
实例),所以我想知道是否可以直接传递函数或事件?