Skip to content

Commit 06c801c

Browse files
committed
refactor: 重构代码
1 parent 6f6fb08 commit 06c801c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/BootstrapBlazor/Components/AutoFill/AutoFill.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
}
2828
else
2929
{
30-
<div>@OnGetDisplayText(item)</div>
30+
<div>@GetDisplayText(item)</div>
3131
}
3232
</li>
3333
}

src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ protected override void OnParametersSet()
115115
Icon ??= IconTheme.GetIconByKey(ComponentIcons.AutoFillIcon);
116116
LoadingIcon ??= IconTheme.GetIconByKey(ComponentIcons.LoadingIcon);
117117

118-
OnGetDisplayText ??= v => v?.ToString();
119-
_displayText = Value is null ? "" : OnGetDisplayText(Value);
120-
118+
_displayText = GetDisplayText(Value);
121119
Items ??= [];
122120
}
123121

@@ -127,14 +125,16 @@ protected override void OnParametersSet()
127125
private async Task OnClickItem(TValue val)
128126
{
129127
CurrentValue = val;
130-
_displayText = OnGetDisplayText(val);
128+
_displayText = GetDisplayText(val);
131129

132130
if (OnSelectedItemChanged != null)
133131
{
134132
await OnSelectedItemChanged(val);
135133
}
136134
}
137135

136+
private string? GetDisplayText(TValue item) => OnGetDisplayText?.Invoke(item) ?? item?.ToString();
137+
138138
private List<TValue> Rows => _filterItems ?? Items.ToList();
139139

140140
/// <summary>
@@ -157,8 +157,8 @@ public async Task TriggerFilter(string val)
157157
{
158158
var comparision = IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
159159
var items = IsLikeMatch
160-
? Items.Where(i => OnGetDisplayText(i)?.Contains(val, comparision) ?? false)
161-
: Items.Where(i => OnGetDisplayText(i)?.StartsWith(val, comparision) ?? false);
160+
? Items.Where(i => OnGetDisplayText?.Invoke(i)?.Contains(val, comparision) ?? false)
161+
: Items.Where(i => OnGetDisplayText?.Invoke(i)?.StartsWith(val, comparision) ?? false);
162162
_filterItems = items.ToList();
163163
}
164164

0 commit comments

Comments
 (0)