Wt: Wt::WJavaScriptHandle< T > Class Template Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Wt::WJavaScriptHandle< T > Class Template Reference

A handle to a JavaScript representation of an object. More...

`#include <Wt/WJavaScriptHandle.h>`

## Public Member Functions
| WJavaScriptHandle () noexcept
| Create an invalid WJavaScriptHandle.
| WJavaScriptHandle (const WJavaScriptHandle &handle) noexcept
| Copy constructor.
WJavaScriptHandle & | operator= (const WJavaScriptHandle &handle) noexcept
| Copy assignment operator.
| WJavaScriptHandle (WJavaScriptHandle &&handle) noexcept
| Move constructor.
WJavaScriptHandle & | operator= (WJavaScriptHandle &&handle) noexcept
| Move assignment operator.
| ~WJavaScriptHandle ()
| Destructor.
bool | isValid () const noexcept
| Returns whether this is a valid handle.
std::string | jsRef () const
| Returns the JavaScript representation of the object.
void | setValue (const T &v)
| Set the value for this handle.
const T & | value () const
| Get the value for this handle.

## Detailed Description

template<typename T>
class Wt::WJavaScriptHandle< T >

A handle to a JavaScript representation of an object.

A WJavaScriptHandle allows to access and modify an object in JavaScript. This is useful to avoid server roundtrips when frequently updating something, e.g. to interact with and animate a WPaintedWidget.

You can use the value() of a WJavaScriptHandle just as you would normally, with the exception that it will be JavaScript bound, and so will any copies you make of it. You should not modify a JavaScript bound object, as this will not change its client side representation. Use the handle's setValue() method instead.

You can access (and modify) the value of a handle on the client side using jsRef().

You can update the value from the server with setValue(). Changes on the client side will be synced back to the server.

Currently, only WPaintedWidget allows the use of JavaScript exposable objects.

See also
  WJavaScriptExposableObject, WPaintedWidget

## Constructor & Destructor Documentation

## ◆ WJavaScriptHandle()

template<typename T >

Wt::WJavaScriptHandle< T >::WJavaScriptHandle | ( |  | ) |
| noexcept

Create an invalid WJavaScriptHandle.

The handle will be invalid until a valid WJavaScriptHandle is copy-assigned to it.

## Member Function Documentation

## ◆ isValid()

template<typename T >

bool Wt::WJavaScriptHandle< T >::isValid | ( |  | ) | const
| noexcept

Returns whether this is a valid handle.

A handle is not valid if it is not connected to a JavaScript representation. To make a WJavaScriptHandle valid, a valid WJavaScriptHandle has to be copy-assigned to it. The various createJS... methods in WPaintedWidget return a valid handle.

## ◆ jsRef()

template<typename T >

std::string Wt::WJavaScriptHandle< T >::jsRef | ( |  | ) | const

Returns the JavaScript representation of the object.

You can access and modify the value of this handle through its jsRef().

Exceptions

  WException | The handle is invalid

## ◆ setValue()

template<typename T >

void Wt::WJavaScriptHandle< T >::setValue | ( | const T & | v | ) |

Set the value for this handle.

The value may not be JavaScript bound, i.e. related to another WJavaScriptHandle. The change to the value will be synced to the client side equivalent.

Exceptions

  WException | The handle is invalid
  WException | Trying to assign a JavaScript bound value

## ◆ value()

template<typename T >

const T & Wt::WJavaScriptHandle< T >::value | ( |  | ) | const

Get the value for this handle.

Warning
  You should not modify this value or any copy of it on the server side, because this will not be synced to the client side. Use setValue() instead.

Exceptions

  WException | The handle is invalid