Issue #1493Opened October 9, 2018by dancodes0 reactions

[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)

artfOctober 11, 20180 reactions

@dancodes can you provide a live demo of the issue, please?

no-response[bot]October 21, 20180 reactions

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.

lock[bot]October 21, 20190 reactions

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...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.