gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:01:17 25 4
gpt4 key购买 nike

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

父组件

<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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com