问题
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:
- Listen to
liszt:ready
event - Apply chosen
- 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