ManuelDeLeon / viewmodel

MVVM for Meteor
https://viewmodel.org
MIT License
205 stars 23 forks source link

How to Bind Some dynamically create elements? #298

Open fhgs2001 opened 7 years ago

fhgs2001 commented 7 years ago

Hi I would like to ask how can I bind element that is dynamically created using javascript? E.g. I created a textarea using summernote plugin $(element).summernote(). The element textarea does not exist before I created it through an add button.How can I bind the textarea element?

arggh commented 7 years ago

You should probably initialize Summernote with a callback that updates your vm property, approximately like so:

Template.editor.viewmodel({
  myText: '',

  onRendered() {
     this.editorElement.summernote({ // $('#myEditorDiv').summernote(...
       callbacks: {
          onChange: (contents) {
             this.myText(contents);
          }
       }
    });
  }
});