grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

[Question] updating the model/view content

Open roytang opened this issue 9 years ago • 3 comments

Hi,

I'm writing a custom component where I want to modify the content of the component after it's dropped. I made a simple test by combining some examples I found somewhere:

    view: defaultType.view.extend({
      init() {
        this.listenTo(this.model, 'active', this.doStuff); // listen for active event
      },
      doStuff() {
        var randomHex = function() {
          return '#' + Math.floor(Math.random()*16777216).toString(16);
        };
        // this is reflected on the canvas
        this.model.set('style', {color: randomHex()}); 
        // this is reflected only in the generated HTML
        this.model.set('content', 'TEST');
      }

The issue I have, as reflected in the comments above, is that updating the content doesn't reflect in the canvas, but when I extract the HTML from the editor to save it, the change is reflected. How can I make it so that the change to the model is reflected "live"? Or do I just have to also update the view's element myself?

Thanks!

roytang avatar Jul 23 '17 03:07 roytang

Please ignore. I was able to make it work by adding a call to view.render()

roytang avatar Jul 23 '17 04:07 roytang

@roytang this just helped me so much thanks for posting the answer

dmac1025 avatar Nov 24 '17 21:11 dmac1025

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Sep 18 '19 06:09 lock[bot]