为什么select2-removal事件不会在带有allowClear的select2中触发? [英] Why does the select2-removing event not trigger in select2 with allowClear?

查看:294
本文介绍了为什么select2-removal事件不会在带有allowClear的select2中触发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在 select2 中清除一个事件。 select2被初始化为 allowClear:true 。然而事件

I want to hook an event in my select2 once it gets cleared. The select2 was initalized with allowClear: true. Yet the event

$select.on('select2-removed', function(event) {
    console.log(event);
});

在使用清除按钮重置select2时不会触发。

does not trigger when resetting the select2 with the clear button.

推荐答案

根据select2源代码, clear 方法使用事件 select2-清除而不是 select2-removal 。所以你也应该听这个事件。

According to the select2 source code, the clear method use the event select2-clearing instead of select2-removing. So you should listen to this event too.

select2-clearing select2-removal 在删除之前触发 select2-removed 在之后被触发。

select2-clearing and select2-removing are triggered before the removal. select2-removed is triggered after.

请记住 clear 并不总是触发 select2-removed 事件。看起来只有在实际从输入中删除元素时才会触发此事件。

Keep in mind that clear does not always trigger the select2-removed event. It look like this event is triggered only if an element is actually removed from the input.

这篇关于为什么select2-removal事件不会在带有allowClear的select2中触发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆