Skip to content

Commit 8fe9940

Browse files
committed
refactor: 更改变量名称
1 parent 9ddc54f commit 8fe9940

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<span class="form-select-append"><i class="@Icon"></i></span>
1818
<span class="form-select-append ac-loading"><i class="@LoadingIcon"></i></span>
1919
<ul class="dropdown-menu">
20-
@foreach (var item in _items)
20+
@foreach (var item in FilterItems)
2121
{
2222
<li @key="item" class="dropdown-item" @onclick="() => OnClickItem(item)">
2323
@if (ItemTemplate == null)
@@ -30,7 +30,7 @@
3030
}
3131
</li>
3232
}
33-
@if (ShowNoDataTip && _items.Count == 0)
33+
@if (ShowNoDataTip && FilterItems.Count == 0)
3434
{
3535
<li class="dropdown-item">@NoDataTip</li>
3636
}

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ public partial class AutoComplete
100100
[NotNull]
101101
private IStringLocalizer<AutoComplete>? Localizer { get; set; }
102102

103-
private List<string> _items = [];
103+
/// <summary>
104+
/// 获得/设置 UI 呈现数据集合
105+
/// </summary>
106+
[NotNull]
107+
protected List<string>? FilterItems { get; set; }
104108

105109
/// <summary>
106110
/// 获得 是否跳过 ESC 按键字符串
@@ -139,13 +143,13 @@ protected override void OnParametersSet()
139143
Icon ??= IconTheme.GetIconByKey(ComponentIcons.AutoCompleteIcon);
140144
LoadingIcon ??= IconTheme.GetIconByKey(ComponentIcons.LoadingIcon);
141145

142-
_items = Items?.ToList() ?? [];
146+
FilterItems = Items?.ToList() ?? [];
143147
}
144148

145149
/// <summary>
146150
/// 鼠标点击候选项时回调此方法
147151
/// </summary>
148-
protected virtual async Task OnClickItem(string val)
152+
protected async Task OnClickItem(string val)
149153
{
150154
CurrentValue = val;
151155
if (OnSelectedItemChanged != null)
@@ -164,20 +168,20 @@ public async Task TriggerOnChange(string val)
164168
if (OnCustomFilter != null)
165169
{
166170
var items = await OnCustomFilter(val);
167-
_items = items.ToList();
171+
FilterItems = items.ToList();
168172
}
169173
else
170174
{
171175
var comparison = IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
172176
var items = IsLikeMatch
173177
? Items.Where(s => s.Contains(val, comparison))
174178
: Items.Where(s => s.StartsWith(val, comparison));
175-
_items = items.ToList();
179+
FilterItems = items.ToList();
176180
}
177181

178182
if (DisplayCount != null)
179183
{
180-
_items = _items.Take(DisplayCount.Value).ToList();
184+
FilterItems = FilterItems.Take(DisplayCount.Value).ToList();
181185
}
182186

183187
CurrentValue = val;

0 commit comments

Comments
 (0)