jquery - Rendering bootstrap modal using backbone -


i think code explain better problem: view:

app.views.errormodal = backbone.view.extend({   template: window.template('errormodal'),    render: function(){     this.$el.html(this.template(this.model.tojson()));      this.$("#errorapprovemodal").modal({         keyboard: true     });      return this;    }  }); 

when instantiating:

 var error = new app.models.errors({title: "exporting error", content: "error"});  var errormodal = new app.views.errormodal({model: error});  errormodal.render(); 

the modal loaded empty div

thanks help! roy

it better create separate class holds modal logic , call master view.

try using this approach.

modal js

var basemodalview = backbone.view.extend({      id: 'base-modal',     classname: 'modal fade hide',     template: 'modals/basemodal',      events: {       'hidden': 'teardown'     },      initialize: function() {       _.bindall(this, 'show', 'teardown', 'render', 'renderview');       this.render();     },      show: function() {       this.$el.modal('show');     },      teardown: function() {       this.$el.data('modal', null);       this.remove();     },      render: function() {       this.gettemplate(this.template, this.renderview);       return this;     },      renderview: function(template) {       this.$el.html(template());       this.$el.modal({show:false}); // dont show modal on instantiation     }  }); 

handlebars template

<div class="modal-dialog">   <div class="modal-content">     <div class="modal-header">       <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>       <h4 class="modal-title">modal title</h4>     </div>     <div class="modal-body">       ...     </div>     <div class="modal-footer">       <a href="#" class="btn">close</a>       <a href="#" class="btn btn-primary">save changes</a>     </div>   </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> 

parent view // on button click following fired

modalview = new basemodalview(); modalview.show();  // modal view automatically bound body , removes on hidden; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -