绑定到选择的事件:就绪事件 [英] Binding to Chosen liszt:ready event

查看:119
本文介绍了绑定到选择的事件:就绪事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用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:

  1. 收听liszt:ready事件
  2. 应用选择
  3. 手动触发liszt:ready
  1. Listen to liszt:ready event
  2. Apply chosen
  3. 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屋!

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