[英]How to capture event when allowClear option of select2 is chosen?
I've tried to capture select2:clearing
event我试图捕获
select2:clearing
事件
$("#my-select").on("select2:clearing", function (e) {
console.log('cleared');
});
but it is not fired.但它没有被解雇。 I've also tried other versions (like
select2:removed
etc., see another question with similar problem), but it also doesn't work.我也尝试过其他版本(如
select2:removed
等,请参阅另一个有类似问题的问题),但它也不起作用。
I use select2 4.0.0-beta2.我使用 select2 4.0.0-beta2。
The changelog of select2 4.0.0-beta2 states: select2 4.0.0-beta2 的更新日志指出:
Removed events
删除的事件
select2-clearing - Use select2:unselecting instead
https://github.com/select2/select2/releases https://github.com/select2/select2/releases
This works:这有效:
$("#my-select").on("select2:unselecting", function(e) {
});
$("#my-select").on("select2:select select2:unselecting", function(e) {
//do something here
});
According to the select2 event documentations , all of the unselect, unselecting, clear and clearing events will works !
根据 select2事件文档,所有取消选择、取消选择、清除和清除事件都将起作用!
But consider that usnselect or unselecting events should be used by single selection mode, and clear or clearing should be used by multi selection mode.但考虑到usnselect或取消选择事件应该由单一选择模式中使用,并清除或清除应多选择模式中使用。 So the clear or clearing will fires if all of selected items cleared or clearing.
因此,如果所有选定的项目都被清除或清除,清除或清除将被触发。
The differences between unselect and unselecting, is that unselecting fires before removing selection so you can prevented it.取消选择和取消选择之间的区别在于取消选择会在删除选择之前触发,因此您可以阻止它。
Hope that it helps.希望它有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.