Last active
March 25, 2019 02:33
-
-
Save scottsauber/2a849fb4ad1b9c204a0ee44bfc0d41f0 to your computer and use it in GitHub Desktop.
Bind example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@page "/" | |
<input bind="@SearchTerm" /> | |
<span class="text-muted ml-5"> | |
Showing @FilteredToDos.Count out of @ToDoItems.Count | |
</span> | |
<h4 class="mt-4">To Do's</h4> | |
<ul> | |
@foreach (var toDo in FilteredToDos) | |
{ | |
<li>@toDo.Name</li> | |
} | |
</ul> | |
@functions { | |
// Initialize SearchTerm to "" to prevent null's | |
string SearchTerm { get; set; } = ""; | |
// Imagine this was retrieved from an API, just hardcoding for demo purposes | |
List<ToDoItem> ToDoItems => new List<ToDoItem> | |
{ | |
new ToDoItem { Name = "Garbage" }, | |
new ToDoItem { Name = "Dishes" }, | |
new ToDoItem { Name = "Wash clothes" }, | |
new ToDoItem { Name = "Water flowers" } | |
}; | |
List<ToDoItem> FilteredToDos => ToDoItems.Where(i => i.Name.ToLower().Contains(SearchTerm.ToLower())).ToList(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment