Search Support
-
Vignesh DhakshinamoorthyFebruary 8, 2017 at 12:05 pm #3639
I find it very handy to call a inline javascript function from a control’s event.
For example, I can access this in an onClick event using @refresh();this.refresh = function(){ console.log("refresh block"); }
But when I define a static variable like this and access it using @name, it gives an ILLEGAL Character error on load.
this.name = "Spark"
How can I access the variables? Seems straightforward but can’t get it to work!SPARK SupportFebruary 15, 2017 at 4:26 pm #3729Hi Vignesh,
What variables are you trying to access?
Let’s say you wanted to access the color configuration variable. In that case, the inline JS could contain:
this.colorSetter = function(color) {
this.context.options.color.set(“value”,color);
return true;
}And you could call from the inline On Click event:
me.colorSetter(“blue”);
Regards,
Stephen P.
Vignesh DhakshinamoorthyFebruary 20, 2017 at 10:36 am #3779Hi Stephen, thank you for your reply. In my case, I am not trying to access a configuration option, but a global constant declared at the coach view level. In my example, the function “this.refresh” declared at the coach view level is accessible by all the controls inside that coach view using the syntax “@refresh()”. I am wondering why the same does not work for a variable declared in a similar fashion like this.myConstant = 10; and access it as @myConstant in a event handing script?
SPARK SupportFebruary 22, 2017 at 9:39 am #3794Hi Vignesh,
No, this does not work the same way. Variables need to be passed and returned by argument.
The @ notation simply makes it easier for the developer to call a function that provides some handling from an event. Note that this notation does not allow for arguments to be passed.
Regards,
Stephen P.
Vignesh DhakshinamoorthyFebruary 22, 2017 at 10:25 am #3798Thank you Stephen, for clarifying the API.
-
|
You must be logged in to reply to this topic.