简体   繁体   English

select2:输入更改时启动功能

[英]select2 : launch function when input change

I use a select2 tag to choose a selection of users from the database. 我使用select2标记从数据库中选择一组用户。 The problem is that the users database is huge, I don't want to have a list of a thousand possibilities while using select2. 问题是用户数据库很大,我不想在使用select2时有上千种可能性的列表。

I want the possibilites to change only when I type in the input field. 我希望仅在输入字段中键入时才可能更改。 Like a ng-change, but ng-change only works when you add or remove a choice in your model. 就像ng-change一样,但是ng-change只能在模型中添加或删除选择时起作用。

Ex : I would have an empty list at beginning, and if I type "Mike" I would have all users who are called "Mike" 举例:我一开始会有一个空列表,如果我输入“ Mike”,我将拥有所有被称为“ Mike”的用户

<select2 multiple placeholder="Choose users" ng-model="usersSelection" s2-options="user.id as user.name for user in users"></select2>

Do you know how I could do that ? 你知道我该怎么做吗? select2 code is huge, I'm just searching for a simple solution, like a watch function. select2代码非常庞大,我只是在寻找一种简单的解决方案,例如监视功能。

Thanks, and sorry for my english. 谢谢,对不起我的英语。

I don't know angularjs , but can't you use the property minimumInputLength when initializing the select2 box? 我不知道angularjs ,但是初始化select2框时不能使用属性minimumInputLength吗?

$("#element").select2({
    minimumInputLength: 3,
    ...
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM