Project

General

Profile

Actions

Support #11419

closed

Javascript objects, classes and variables

Added by Momo LALMI about 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
03/09/2023
Due date:
% Done:

0%

Estimated time:

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

Actions #1

Updated by Roel Standaert about 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).

Actions #2

Updated by Momo LALMI about 1 year ago

many thanks for your help.

Actions #3

Updated by Roel Standaert about 1 year ago

  • Status changed from New to Closed
Actions

Also available in: Atom PDF