I have a plugin called select2, I normally invoke the plugin inside my javascript file like this: $(document).ready(function() { $("#e1").select2(); });
but on my Batman app I'm not sure where should I put it. I could place it inside the libs folder (my_helper.js)but it doesn't work, is there another place where conventionally this jquery call should go?
Thanks.
EDIT: This can get more complicated if you have a
data-foreach
to generate the options. I've added a more robustSelect2View
at the end of this answer!I'm guessing document.ready is fired before Batman views actually render, so the DOM isn't populated yet. The jQuery call doesn't match any elements, since they aren't on the page yet.
Try defining a custom view, hooking into its lifecycle, then binding to that view in your HTML.
Custom view:
in your HTML:
More about view lifecycle callbacks here: http://batmanjs.org/docs/views.html#view-lifecycle
Other Select2View:
(Also on pastebin)