本文介绍了如何传递List< string>作为blazor中子组件的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想做的事的一个例子:

Here's an example of what I'd like to do:

父项

<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文档中找不到关于此操作的任何信息.我指的不是泼溅.

I feel like I'm doing something wrong since I can't find anything in blazor docs about doing this. I'm not referring to splatting.

推荐答案

您可以通过多种方式进行操作.这是一个:

You can do it in a variety of ways. This is one:

<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"};
} 

这篇关于如何传递List&lt; string&gt;作为blazor中子组件的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 17:04