Read the statement by Michael Teeuw here.
Help with updateDom()
-
@UjwalReddy267
I would do this:
the count variable out of defaults and intothis
. Then count it up in getdom.Module.register("MMM-Test",{ default: {loc: ["modules/MMM-Test/test1.jpg","modules/MMM-Test/test.jpg"]}, count: 0, start : function(){ setInterval(function() {this.updateDom()}, 1000); }, getDom : function (){ var wrapper = document.createElement('div') wrapper.id = 'FULL' var img = document.createElement('div') var i = this.count img.style.backgroundImage = 'url(' + this.config.loc[i] + ')' img.id = 'photo' var blr = document.createElement('div') blr.id = 'backgrnd' blr.style.backgroundImage = 'url(' + this.config.loc[i] + ')' wrapper.appendChild(blr) wrapper.appendChild(img) this.count = (this.count + 1) % 2 return wrapper }, getStyles : function (){ return ['MMM-Test.css'] } }) ``
-
@lavolp3 are you sure the image url is correct?
I would always for debugging purposes print that out once.console.log('url(' + this.config.loc[i] + ')'); console.log(this.count)
Or check the dev console for errors not finding the pictures.
-
@UjwalReddy267 your pointer ‘this’ is wrong inside the timer handle
setInterval(function() {this.updateDom()
you need to do
var self=this
and in the handler use self instead
setInterval(function() {self.updateDom()
-
@lavolp3 NOw I have the error, I think!
the
this
in the interval might refer to another this and not to the original module-this
So you need to do the following in start:start : function(){ var self = this; setInterval(function() {self.updateDom()}, 1000); },
-
@sdetweil You were faster sam!
-
This post is deleted! -
@sdetweil said in Help with updateDom():
@UjwalReddy267 your pointer ‘this’ is wrong inside the timer handle
setInterval(function() {this.updateDom()
you need to do
var self=this
and in the handler use self instead
setInterval(function() {self.updateDom()
Yes, that was the error, thank you it works now.
-
better use this …
start : function(){ setInterval( () => {this.updateDom()}, 1000); },