backbone.js - wait for backbone template to be appended to the dom -


i trying bind events elements placed appending backbone template:

 appendedittemplateandsetevents: function() {                 var associatedcollection = app.helpers.findassociatedcollection(this.allcollections, this.associatedcollectionid);                 var template = this.setedittemplateforelement(associatedcollection.type);                 var modalbody = this.$el.find('.modal-body');                  modalbody.empty();                  var firstmodel = associatedcollection.at(0);                  if(template.maintemplate !== null) {                     modalbody.append($('#edit-form-element-frame').html());                      //each mode in collection                     associatedcollection.each(function(model){                         if(model.get('positionincontainer') === 1) {                             firstmodel = model;                         }                         console.log(model.attributes);                         modalbody.find('.elements-in-editmodal-wrapper').append(template.maintemplate(model.tojson()));                     });                 }                  if( template.templatevalidation.length !== 0 ) {                     modalbody.append('<hr><h3>validateregels</h3>');                     _.each(template.templatevalidation, function(val, index) {                         modalbody.append(val(firstmodel.tojson()));                     });                 }                  //set listeners , handlers apply when edit modal open                 this.validationeventsforeditmodal(firstmodel);                 this.editerrormessagesinmodal(firstmodel);             }, 

now problem when last 2 functions called html of templates isn't appended yet the events binded object length of 0.

does have decent solution async problem? tried $.defferred did not work, maybe get's working.

i solved using this.$el.find(...) in functions:

this.validationeventsforeditmodal(firstmodel); this.editerrormessagesinmodal(firstmodel); 

i don't know if it's still async problem, solves it.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -