Use jQuery in view update
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)
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.
@isvaljek use this.$el instead of this.el
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.
Issue #1618
Child components are not tracked in models ??
Hi, I'm facing as strange issue and I need your help. when I move components inside blocks, at the view model the changes successfully appl...
Issue #1727
[QUESTION] Event to get children view
I have a problem with a component. When I drop a component into the canvas I create a simple object. Before appending this object I need to...
Issue #828
[QUESTION] Components 'add' event fires different number of times
Hi, I've noticed that if I add the following code in my custom component the event fires differently depending on whether a new child compo...
Issue #1448
Child component not selectable when using custom view
I'm trying to create a custom component that creates it's own view with nested HTML. I do not want this HTML to be rendered as a component...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.