SimpleStorage is an object storage. Just like the Map object in JavaScript, it 's is a collection of key/value, and keys (or values), where the keys can be of any type.
Methods Use the methods of this class can be used. For , for example, in the widget client scripts to operate with the objects. See the code example below for more clarity.:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | Storage usage |
---|
linenumbers | true |
---|
|
if (SimpleStorage.hasItem('portalLogo')) {
s_widget.setFieldValue("HasLogo", true);
s_widget.setFieldValue("logo", SimpleStorage.getItem("portalLogo"));
} else {
await s_widget.serverUpdate();
SimpleStorage.setItem('portalLogo', s_widget.getFieldValue("logo"));
} |
getItem(key)
Gets Use this method to get a value based on a the key.
Name | Type | Mandatory | Default Value |
---|
key | String | Y | N |
Return:
Type | Description |
---|
String | This method returns an item specified by a key. |
Example:
Code Block |
---|
language | xml |
---|
title | getItem |
---|
linenumbers | true |
---|
|
SimpleStorage.getItem('name'); // "Adam" |
hasItem(key)
Checks Use this method to check if there 's is a key in the storage.
Parameter:
Name | Type | Mandatory | Default value |
---|
key | Any | Y | N |
Return:
Type | Description |
---|
Boolean | This method returns 'true' if the key specified in the key parameter was found; otherwise, it returns 'false'. |
Example:
Code Block |
---|
language | xml |
---|
title | hasItem |
---|
linenumbers | true |
---|
|
SimpleStorage.hasItem('name'); // true |
setItem(key, value)
Sets the Use this method to set a value based on a key.
Parameters:
Name | Type | Mandatory | Default Value |
---|
key | String | Y | N |
value | Any | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | xml |
---|
title | setItem |
---|
linenumbers | true |
---|
|
SimpleStorage.setItem('name', 'Adam') |
getEntries()
Gets Use this method to get an array of pairs (value, key).
Type | Description |
---|
Array | This method returns an array containing value pairs; otherwise, it returns an empty array. |
Example:
Code Block |
---|
language | xml |
---|
title | getEntries |
---|
linenumbers | true |
---|
|
SimpleStorage.getEntries(); // [["name", "Adam"],[ ["secondName", "Smith"]]] |
getKeys()
Gets Use this method to get an array of keys.
Return:
Type | Description |
---|
Array | This method returns an array containing values; otherwise, it returns an empty array. |
Example:
Code Block |
---|
language | xml |
---|
title | getKeys |
---|
linenumbers | true |
---|
|
SimpleStorage.getKeys(); // ["name", "secondName"] |
getSize()
Gets Use this method to get the amount of the values stored.
Example:
Code Block |
---|
language | xml |
---|
title | getSize |
---|
linenumbers | true |
---|
|
SimpleStorage.getSize(); // 2 |
reset()
Empties Use this method to empty the storage.
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | reset |
---|
|
SimpleStorage.reset(); |