MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. ameenaziz
    3. Posts
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    A
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 2
    • Groups 0

    Posts

    Recent Best Controversial
    • RE: How to pass a value between functions in a Module?

      @ninjabreadman thanks for the guidance, the new modules is pretty complex, is there a simpler module to take an example from?

      All I’m really after is the data produced from the trainSchedule function to be accessible by the getDom function.

      posted in Development
      A
      ameenaziz
    • How to pass a value between functions in a Module?

      Hi,

      I’m trying to pass the value in the variable ajaxResult to the getDom function so that I can render it into a table.

      I’ve tried to return the value from the start function but that comes up as undefined

      How are values passed between these functions?

      Thanks for the help in advance

      `/* global Module */

      Module.register(“trainScheduler”,{

      // Default module config.
      defaults: {
      	text: "| --- | --- | --- | --- |"
      },
      
      currentWeatherType: "",
      
      // Define required scripts.
      getScripts: function() {
      	return ["moment.js"];
      },
      
      // Define start sequence.
      start: function() {
      	Log.info("Starting module: " + this.name);
      
      	var ajaxResult; 
      
      	// Log.info('RESULT' + ajaxResult);
      
      	if (this.config.remoteFile != null) {			
      		this.trainSchedule(
      			(response) => {				
      				this.config = JSON.parse(response);
      				//function call to send the result to out!
      				responseRunner(response);
      				
      			}
      		);
      		function responseRunner (response) {
      			ajaxResult = response;
      		};
      
      	}
      
      	// Schedule update timer.
      
      	// LEMME COME BACK TO THIS AUTO REFERESHER THING
      
      	// var self = this;
      	// setInterval(function() {
      	// 	self.updateDom(self.config.fadeSpeed);
      	// }, this.config.updateInterval);
      },
      
      /* complimentFile(callback)
       * Retrieve a file from the local filesystem
       */
      trainSchedule: function(callback) {
      	var xobj = new XMLHttpRequest();
      	xobj.overrideMimeType("application/json");
      	xobj.open("GET", this.file(this.config.remoteFile), true);
      	xobj.onreadystatechange = function() {
      		if (xobj.readyState == 4 && xobj.status == "200") {
      			callback(xobj.responseText);
      		}
      	};
      	xobj.send(null);
      	
      },
      
      // Override dom generator.
      getDom: function() {
      
      	var complimentText = 1;
      	var compliment = document.createTextNode(complimentText);
      	var wrapper = document.createElement("div");
      	wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright";
      	wrapper.appendChild(compliment);
      
      	return wrapper;
      },
      

      });
      `

      posted in Development
      A
      ameenaziz
    • 1 / 1