绑定到选择的事件:就绪事件 [英] Binding to Chosen liszt:ready event
问题描述
我们正在使用jQuery Chosen插件将HTML select
转换为漂亮的可搜索列表.我正在尝试的是在选择已就绪(即触发liszt:ready
)之后在列表的底部添加一个链接.
We are using jQuery Chosen plugin to convert the HTML select
to a nice searchable list. What I am trying is to add a link at the bottom of list after the Chosen is ready (i.e. liszt:ready
is triggered).
我可以使用以下代码轻松绑定到liszt:showing_dropdown
,并且效果很好:
I can easily bind to liszt:showing_dropdown
with the following code and it works just fine:
$("select").chosen().on("liszt:showing_dropdown", function(){
console.log "List opened."
})
但是,当我尝试用liszt:ready
替换liszt:showing_drop
时,它不起作用.我认为这很正常,因为liszt:ready
在执行$("select").chosen()
时触发.
However, when I try to replace liszt:showing_drop
with liszt:ready
it doesn't work. I think this is normal because the liszt:ready
triggers when $("select").chosen()
gets executed.
以下是触发liszt:ready
事件的jquery.chosen.js的摘录:
Here is the excerpt from jquery.chosen.js which triggers the liszt:ready
event:
...
this.results_build();
this.set_tab_index();
return this.form_field_jq.trigger("liszt:ready", {
chosen: this
});
...
有人可以指导我如何绑定到liszt:ready
事件吗?
Could someone please guide me how to bind to liszt:ready
event?
推荐答案
我不确定这样做是否正确,但对我有用:
I'm not sure if it's the right way to do it but it works for me:
- 收听
liszt:ready
事件 - 应用选择
- 手动触发
liszt:ready
- Listen to
liszt:ready
event - Apply chosen
- Trigger
liszt:ready
manually
收听liszt:ready
事件:
$("select").on("liszt:ready", function(){
console.log("Hey, I am ready!");
})
然后应用选择并手动触发liszt:ready
Then apply Chosen and trigger the liszt:ready
manually
("select").chosen().trigger("liszt:ready");
请告诉我是否有一些更合适的方法来实现这一目标.
Please let me know if there is some more appropriate way to achieve this.
这篇关于绑定到选择的事件:就绪事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!