kony.store Namespace
The kony.store Namespace provides the following API elements.
Functions
The kony.store
namespace provides the following functions.
This API allows you to empty the database by clearing all the key-value pairs. If there are no key-value pairs, then the API does not do anything.
Syntax
kony.store.clear();
Input Parameters
None
Example
try { kony.store.clear(); alert("store is cleared"); } catch (err) { alert("error occurred in clear() and the error is :" + err); }
Return Values
None
Exceptions
LocalStorageError
Error
Implementation Details
For implementation details, see http://www.w3.org/TR/webstorage/#the-localstorage-attribute.
Platform Availability
Available on all platforms.
This API returns a structured clone of the current value associated with the given key. If the given key does not exist in the list associated with the object then this method returns null for JavaScript.
Syntax
kony.store.getItem(keyname);
Input Parameters
Parameter | Description |
---|---|
keyname [String] - Mandatory | Specifies the keyname from which the item needs to be fetched. |
Example
var myValue = kony.store.getItem("name"); alert("name is " + myValue);
Return Values
Return Value | Description |
---|---|
myitem [Object] | Returns the item located at the specified index. |
Exceptions
LocalStorageError
Error
Implementation Details
For implementation details, see http://www.w3.org/TR/webstorage/#the-localstorage-attribute.
Platform Availability
Available on all platforms.
This API removes the item identified by the key, if it exists. If no item with that key exists, the method does not perform any action.
Syntax
kony.store.removeItem(keyname);
Input Parameters
Parameter | Description |
---|---|
keyname [String] - Mandatory | Specifies the keyname for which the item needs to be removed. |
Example
kony.store.removeItem("name"); alert("name removed");
Return Values
None
Exceptions
LocalStorageError
Error
Implementation Details
For implementation details, see http://www.w3.org/TR/webstorage/#the-localstorage-attribute.
Platform Availability
Available on all platforms.
This API creates a structured clone of the given value. If this raises an exception then the list associated with the object is left unchanged.
Syntax
kony.store.setItem(key, value);
Input Parameters
Parameter | Description |
---|---|
key [string] - Mandatory | Specifies the keyname for which the item needs to be set. |
value [object] - Mandatory | Specifies the value that must be set at the given index. This value can be a number, string, Boolean. |
Example
kony.store.setItem("keyValue5", "this is a key value"); kony.store.setItem("keyValue4", true);
Return Values
None
Exceptions
LocalStorageError
Error
Implementation Details
For implementation details, see http://www.w3.org/TR/webstorage/#the-localstorage-attribute.
Platform Availability
Available on all platforms.
This API returns the name of the nth key in the list. If n is greater than the number of key/value pairs in the object, then this method returns null for JavaScript.
Syntax
kony.store.key(index);
Input Parameters
Parameter | Description |
---|---|
index [Number] - Mandatory | Specifies the index for which the key name is to be returned. |
Example
var keyName = kony.store.key(0); alert("first key name is " + keyName);
Return Values
Return Value | Description |
---|---|
keyname [String] | Returns the keyname of the specified index. |
null/nil | Returns null/nil when the specified index is greater than the number of key/value pairs in the object. |
Exceptions
LocalStorageError
Error
Implementation Details
For implementation details, see http://www.w3.org/TR/webstorage/#the-localstorage-attribute.
Platform Availability
Available on all platforms.
This API returns the length of the local storage.
Syntax
kony.store.length();
Input Parameters
None
Example
mylength = kony.store.length(); alert("length is " + mylength);
Return Values
Return Value | Description |
---|---|
mylength [String] | Returns the length of the local storage. |
Exceptions
LocalStorageError
Error
Implementation Details
For implementation details, see http://www.w3.org/TR/webstorage/#the-localstorage-attribute.
Platform Availability
Available on all platforms.