0

Good morning guys, all right?

I render a grid with handlebars, after that, I need to adjust the height of the cards and activate another jquery plugin referring to a select options that is rendered by handlebars.

When I call the functions to adjust the height of the cards and activate the aforementioned plugin, right after the handlebars process does not work, but if I put a settimeout, most often works, but AI depends on the speed of the Internet, hard code....

I didn't find any reference to callback in relation to handlebars.

Following part of the code:

    var source   = $("#nome_template").html(); 
    var template = Handlebars.compile(source);
    $('#container_result').html(template(data));

    setTimeout(function() { 
        funcaoAuxiliar();// function that adjusts height and activates the Select options plugin.
    }, 3000); 

Can someone give a help?

Thank you

1 Answers1

0

Depending how your script containing the funcaoAuxiliar function is loaded.

  • If you load it via a script tag : This answer may help you Verify External Script Is Loaded

  • If you load the script via an ajax call : use a callback function (example via jquery below)

$.getScript( "js/funcaoAuxiliar.js", function( data, textStatus, jqxhr ) {
  console.log( data ); // Data returned
  console.log( textStatus ); // Success
  console.log( jqxhr.status ); // 200
  console.log( "Load was performed." );
  // Do your stuff here once script is loaded
  funcaoAuxiliar();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Christophe
  • 2,131
  • 2
  • 21
  • 35