Issue #1553💬 AnsweredOpened October 31, 2018by nine-2-five0 reactions

Use jQuery in view update

快速解答by yomeshgupta

Yes, $ is available would be available under editor.$ However, I am not sure if that would be full fledged jQuery. You can always insert custom JS scripts in the canvas during initialisation. If you want, you can add jQuery there and then it would be available everywhere.

Read full answer below ↓

Question

I need to manipulate DOM with jQuery, when my model changes, but it seems the View is unaware of it.

view: defaultView.extend({
        init() {
          this.listenTo(this.model, 'change:model-twig-path', this.updateContent);
        },
        updateContent() {                        
          var twig_path = this.model.get('model-twig-path');
          var viewEl = this.el;

          request('http://localhost:8080/content/hr.json', function(err, response, data){
              request('http://localhost:8080/static/pharma-bio/views/blocks/' + twig_path, function(err, response, twig_template){
                var template = Twig.twig({data: twig_template});                    

                viewEl.innerHTML = template.render(data);
                //I'd like to use jQuery instead of innerHTML
              });      
          });                                 
        },
      }),

Answers (3)

yomeshguptaOctober 31, 2018

Yes, $ is available would be available under editor.$

However, I am not sure if that would be full fledged jQuery. You can always insert custom JS scripts in the canvas during initialisation. If you want, you can add jQuery there and then it would be available everywhere.

artfNovember 3, 2018

@isvaljek use this.$el instead of this.el

lock[bot]November 3, 2019

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.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.