Binding to Chosen liszt:ready event

拥有回忆 提交于 2019-12-11 09:29:13

问题


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).

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."
})

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.

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
});
...

Could someone please guide me how to bind to liszt:ready event?


回答1:


I'm not sure if it's the right way to do it but it works for me:

  1. Listen to liszt:ready event
  2. Apply chosen
  3. Trigger liszt:ready manually

Listen to liszt:ready event:

$("select").on("liszt:ready", function(){
   console.log("Hey, I am 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.



来源:https://stackoverflow.com/questions/14889466/binding-to-chosen-lisztready-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!