blazor - 如何将 List<string> 作为参数传递给 blazor 中的子组件?

标签 blazor blazor-server-side

这是我想做的事情的示例:

父组件

<MyChildComponent ParamList="{hello, world, this is great}"/>

子组件

<ol>
    @foreach(string myParam in ParamList)
    {
        <li>@myParam</li>
    }
</ol>

@code {
[Parameter]
public List<string> ParamList {get;set;}
}

预期输出

1. Hello
2. World
3. this is great

我觉得我做错了什么,因为我在 blazor 文档中找不到有关执行此操作的任何内容。我指的不是泼溅。

最佳答案

您可以通过多种方式做到这一点。这是一个:

MyChildComponent.razor

<ol>
@foreach (string myParam in ParamList)
{
    <li>@myParam</li>
}
</ol>

@code {
   [Parameter]
   public IReadOnlyList<string> ParamList { get; set; }
}

用法

<MyChildComponent ParamList="list" />

@code{

List<string> list =  new List<string> {"hello", "world", "Angular is great"};
} 

关于blazor - 如何将 List<string> 作为参数传递给 blazor 中的子组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59916846/

相关文章:

razor - 模式在 Blazor 服务器端应用程序中不起作用

c# - Blazor 在 X 量空闲时间后做某事

c# - 开拓者导航: Update URL without changing reloading page

api - Blazor-WASM : Failed to load resource: the server responded with a status of 404 (Not Found)

azure-ad-b2c - 用户登录后如何在 Blazor 服务器端应用程序中检索用户声明?

c# - 在 Blazor 中的 Page 和 NavMenu 之间交换数据

blazor - 将 blazor 组件包含到 MVC View 中(.NET Core 3 Preview #5)

blazor - 如何像Vue一样动态引用razor组件?

c# - 从选项卡注销,不适用于所有其他选项卡

c# - 如何在 Index.razor 页面上为 Blazor 使用谷歌字体