Support #11419
closedJavascript objects, classes and variables
0%
Description
Hello,
Is it possible to declare a javascript variable or object and access is later with WT ?
for example when the WContainerWidget is created :
let myVariable = "string";
and when a WButton is clicked :
myVariable += "string";
without considering the latest as a new variable
Updated by Roel Standaert over 1 year ago
If you want to be able to access this variable at a later point, you need to attach it to the DOM somewhere. Wt has a way to attach members to widgets with setJavaScriptMember. Calling setJavaScriptMember("member", "value")
is roughly equivalent to doing doJavaScript(jsRef() + ".member = value;")
, except that the value you set with setJavaScriptMember
is persisted so that when the widget is rerendered the value gets set again (e.g. when the application is unsuspended, or the widget is removed and re-added).