My situation is this: I'm trying to implement and Autocomplete.
The Autocomplete will have a Parameter
that will receive a string
and return a IEnumerable<TValue>
.
Here is an example of what I'm trying to do
Autocomplete.razor
@code {
[Parameter]
public SOME_TYPE GetItems { get; set; }
async void Foo(){
IEnumerable<TValue> items = await GetItems(SomeString);
// do something with items
}
}
ParentComponent.razor
<Autocomplete TValue="SomeEntity"
GetItems="@GetItems" />
@code {
SOME_TYPE GetItems(string name) {
IEnumerable<SomeEntity> entity = await GetEntitys(name);
return entity;
}
}
The problem is that I don't know what to put in SOME_TYPE
. Should I use EventCallback
? Action
? What should I use?
I tried using EventCallback
but looks like I can't get a return value from EventCallback
? I have no idea.
I just find out how to do it, I should use Func<string, Task<IEnumerable<TValue>>>
.
[Parameter]
public Func<string, Task<IEnumerable<TValue>>> GetItems { get; set; }
And
public async Task<IEnumerable<Employee>> GetItems(string name) {
IEnumerable<SomeEntity> entity = await GetEntitys(name);
return entity;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With