viewmodel icon indicating copy to clipboard operation
viewmodel copied to clipboard

How to Bind Some dynamically create elements?

Open fhgs2001 opened this issue 7 years ago • 1 comments

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?

fhgs2001 avatar Nov 02 '17 15:11 fhgs2001

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);
          }
       }
    });
  }
});

arggh avatar Nov 02 '17 16:11 arggh