Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
SimpleStorage is an object storage. Just like the Map object in JavaScript, it's a collection of key/value, and keys can be of any type.
Methods of this class can be used. for For example, in widget client scripts to operate with objects. See the code example below for more clarity.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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 a value based on a 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 | ||||||
---|---|---|---|---|---|---|
| ||||||
SimpleStorage.getItem('name'); // "Adam" |
hasItem(key)
Checks if there's 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 | ||||||
---|---|---|---|---|---|---|
| ||||||
SimpleStorage.hasItem('name'); // true |
setItem(key, value)
Sets the 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 | ||||||
---|---|---|---|---|---|---|
| ||||||
SimpleStorage.setItem('name', 'Adam') |
getEntries()
Gets an array of pairs (value, key).
Type | Description |
---|---|
Array | This method returns array containing value pairs; otherwise, returns an empty array. |
Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
SimpleStorage.getEntries(); // [["name", "Adam"],[ ["secondName", "Smith"]]] |
getKeys()
Gets an array of keys.
Return:
Type | Description |
---|---|
Array | This method returns array containing values; otherwise, returns an empty array. |
Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
SimpleStorage.getKeys(); // ["name", "secondName"] |
getSize()
Gets the amount of values stored.
Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
SimpleStorage.getSize(); // 2 |
reset()
Empties the storage.
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
SimpleStorage.reset(); |
Table of Contents | ||
---|---|---|
|