[QUESTION] render() works on the first time but not on subsequent calls
Question
Hello,
I've created a custom component that shows images using background-image on a <div> instead of using an <img> element. It's mostly working, except that every time I change its src trait I must reload the editor to preview the rendered element. This is its view:
view: originalMap.view.extend({
initialize: function(o) {
var model = this.model;
// Extend the original initialize method
originalMap.view.prototype.initialize.apply(this, arguments);
this.listenTo(model, 'change:attributes:src', this.render);
},
render: function() {
// Extend the original render method
originalMap.view.prototype.render.apply(this, arguments);
var src = "";
this.model.get('traits').each(function(trait) {
if (trait.get('name') == 'src') {
src = trait.get('value');
}
});
this.$el.css('background-image', 'url("' + src + '")');
return this;
},
})
On editor load, the component has its correct background-image value set. Upon changing its src trait (a text field), it loses that CSS property. What am I doing wrong?
Answers (3)
@dancodes can you provide a live demo of the issue, please?
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
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 #1696
Traits appear first time when draged custom component
Hi artf , i have created custom component and add traits for it , when dragging this component to editor and select it the setting traits w...
Issue #2008
[Question]The canvas turns dark and unmodifiable on adding a large piece of custom html.
I used to add custom html with editor.addComponent(). It works well at most of the time, but when I try to insert a large piece of HTML whi...
Issue #1906
Components & Js - Load Template
Hey, I have a component which has a JS attached to it. Everything is created using the JS. When I drag and drop my block for the first time...
Issue #1255
[QUESTION]: How to set editor html contents from custom component?
I'm having trouble getting a custom block+component to display its template HTML inside the grapes editor. Within the exported HTML, the ma...
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.