Search code examples
jqueryjquery-templates

Create jQuery selectmenu from templated html


If I create HTML with a jQuery-template and then immediately try to reference an item in that HTML to create a jQuery-UI element out of it it doesn't work:

$(".drop-down-container").loadTemplate(...)
$("#directories").selectmenu();     

If I add a setTimeout and only call selectmenu after a delay, it works. Is there some handler I can use so I don't have to count on a delay?

I read elsewhere to use class instead of id, but in my case that makes no difference. Unless I use a delay, class also doesn't work.


Solution

  • As specified in the jquery-template . You can pass have different options to the load template.

    There are a number of options the plugin accepts. These can be set by passing an object containing the settings you would like to set as the third parameter to .loadTemplate:

    $(container).loadTemplate(template, data, { append: true, elemPerPage: 20 });
    

    "complete" (default null) - Callback function to call on complete. Will always be called regardless of success or failure.

    "success" (default null) - Callback function to call on successful completion.

    "error" (default, outputting error message to template container) - Callback function to call on error.

    There are other options available with jquery-template.