我正在使用Telerik的RadAutoComplete来创建自动完成字段。它可以很好地处理静态数据,但根据用户在自动完成字段中接收到的输入,我必须执行API并从那里获取数据。API响应中接收到的列表将在自动完成的建议视图中可见。
当我将回应指派给RadAutoComplete的ItemSource时,在自动完成中输入的文字就会重设。例如:如果我想搜索“星期五”,我在自动完成字段中输入了“Fr”。在收到API的响应后,“Fr”将自动从自动完成中删除,自动完成文本将为“"。
XAML文件:
<telerikInput:RadAutoComplete
BorderColor="LightGray"
FilteredItemsChanged="autoCompleteUsers_FilteredItemsChanged"
ItemsSource="{Binding UserList}"
SearchThreshold="3"
ShowSuggestionView="True"
SuggestionItemSelected="autoCompleteUsers_SuggestionItemSelected"
TextSearchPath="Name">
<telerikInput:RadAutoComplete.SuggestionItemTemplate>
<DataTemplate>
<StackLayout HeightRequest="20">
<Label
Margin="2"
HorizontalOptions="Start"
Text="{Binding Item.Name}"
TextColor="Black"
VerticalOptions="Center" />
</StackLayout>
</DataTemplate>
</telerikInput:RadAutoComplete.SuggestionItemTemplate>
</telerikInput:RadAutoComplete>
事件
void autoCompleteUsers_FilteredItemsChanged(System.Object sender, Telerik.XamarinForms.Input.AutoComplete.FilteredItemsChangedEventArgs e)
{
var searchedText = (sender as RadAutoComplete).Text;
viewController.GetUserList(searchedText);
}
public async Task GetUserList(string searchedText)
{
// **reassigning userList with the response of API**
UserList = await _APIservice.GetUsers(searchedText);
}
1条答案
按热度按时间gfttwv5a1#
尝试使用RadAutoCompleteView,建议用于远程搜索。
https://docs.telerik.com/devtools/xamarin/controls/autocompleteview/autocompleteview-remote-search?_ga=2.230265054.335708323.1661762900-2099335098.1639588237