Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone | Script for document ready
    text
    copied!<p>There is a script(js) which I wish to run on like $(document).ready(). There is a way to write the script in template(e.g. home_tpl.html) file. But I am sure this is not a good way. </p> <p>I am loading the html from a backbone view. I am not using any other wrapper like marionate. Here I wish to run some script when a template is loaded(DOM is loaded). In which way can I write the script?</p> <p>Here is the rendering of view</p> <pre><code> reset: function(key, email){ require(['js/views/reset_password', 'js/models/forgot_password'], function(ResetView, ResetModel){ var resetModel = new ResetModel(); resetModel.set('key', key); resetModel.set('email', email); $('body').html(new ResetView({model: resetModel}).render().el); }); }, </code></pre> <p>Here is the view code</p> <pre><code>define(['text!tpl/reset_passwordtpl.html'],function(Template){ return Backbone.View.extend({ template: _.template(Template), render: function(){ $(this.el).html(this.template()); return this; }, events: { "click #btn_reset_password": "reset" }, reset: function(){ if($('#reset_password').val() != $('#confirm_reset_password').val()){ $('#error_message').text('Passwords mismatched').show(); } else{ $.ajax({ url: server_url + 'reset', type:'POST', dataType:"json", data: {'id': this.model.get('email'), 'key': this.model.get('key'), 'new_password': $('#reset_password').val()}, success:function (data) { if(data.error) { // If there is an error, show the error messages $('.alert-error').text(data.error.text).show(); } else { // If not, send them back to the home page $("#content").html("&lt;h6&gt;Your password is reset. Click &lt;a href='#login'&gt;here&lt;/a&gt; to login.&lt;/h6&gt;"); } } }); } } }); }); </code></pre> <p>thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload