Skip to content

Commit 437cb44

Browse files
committed
refactor: 代码复用
1 parent d4ec920 commit 437cb44

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/BootstrapBlazor/Components/ListView/ListView.razor

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
{
1919
foreach (var item in Rows)
2020
{
21-
<div class="listview-item" @onclick="@(e => OnClick(item))">
22-
@BodyTemplate(item)
23-
</div>
21+
@RenderItem(item)
2422
}
2523
}
2624
else if (Collapsible)
@@ -40,9 +38,7 @@
4038
<div class="accordion-body">
4139
@foreach (var item in key.Items)
4240
{
43-
<div class="listview-item" @onclick="@(e => OnClick(item))">
44-
@BodyTemplate(item)
45-
</div>
41+
@RenderItem(item)
4642
}
4743
</div>
4844
</div>
@@ -83,4 +79,12 @@
8379
@RenderItem(item)
8480
}
8581
</CollapseItem>;
82+
83+
RenderFragment<TItem> RenderItem => item =>
84+
@<div @key="item" class="listview-item" @onclick="@(e => OnClick(item))">
85+
@if(BodyTemplate != null)
86+
{
87+
@BodyTemplate(item)
88+
}
89+
</div>;
8690
}

0 commit comments

Comments
 (0)