A Promise which resolves when this Component has been successfully initialized.
Initializes the object. This method is invoked at the end of the constructor after the object is initialized with the given configuration.
Returns the values of a specified column in an array. The input array should be multidimensional or an array of objects.
For example,
let array = [
{id: '123', data: 'abc'},
{id: '345', data: 'def'},
]
let result = DataHelper.getColumn(array, 'id');
// the result is: ['123', '345']
// using callback
result = DataHelper.getColumn(array, (element) => {
return element['id'];
});
the list of column values
Retrieves the value of an array element or object property with the given key or property name. If the key does not exist in the array, the default value will be returned instead. Not used when getting value from an object.
The key may be specified in a dot format to retrieve the value of a sub-array or the property
of an embedded object. In particular, if the key is x.y.z
, then the returned value would
be array['x']['y']['z']
or array.x.y.z
(if array
is an object). If array['x']
or array.x
is neither an array nor an object, the default value will be returned.
Note that if the array already has an element x.y.z
, then its value will be returned
instead of going through the sub-arrays. So it is better to be done specifying an array of key names
like ['x', 'y', 'z']
.
Below are some usage examples,
// working with array
let username = DataHelper.getValue(POST, 'username');
// working with object
username = DataHelper.getValue(user, 'username');
// working with callback function
let fullName = DataHelper.getValue(user, (user, defaultValue) => {
return user.firstName . ' ' . user.lastName;
});
// using dot format to retrieve the property of embedded object
let street = DataHelper.getValue(users, 'address.street');
// using an array of keys to retrieve the value
let value = DataHelper.getValue(versions, ['1.0', 'date']);
array or object to extract value from
key name of the array element, an array of keys or property name of the object,
or a callback function returning the value. The callback function signature should be:
function(array, defaultValue)
.
the value of the element if found, default value otherwise
Sorts an array of objects or arrays (with the same structure) by one or several keys.
the array to be sorted. The array will be modified after calling this method.
the key(s) to be sorted by. This refers to a key name of the sub-array
elements, a property name of the objects, or a callback function returning the values for comparison
purpose. The callback function signature should be: function(item)
.
To sort by multiple keys, provide an array of keys here.
the sorting direction. It can be either SORT_ASC
or 'SORT_DESC'.
When sorting by multiple keys with different sorting directions, use an array of sorting directions.
the JS sort flag. Valid values include 'SORT_REGULAR', 'SORT_NUMERIC', 'SORT_STRING', 'SORT_LOCALE_STRING', 'SORT_NATURAL' and 'SORT_FLAG_CASE'. for more details. When sorting by multiple keys with different sort flags, use an array of sort flags.
Removes an item from an array and returns the value. If the key does not exist in the array, the default value will be returned instead.
Usage examples,
// let array = {type: 'A', options: [1, 2]};
// working with array
let type = DataHelper.remove(array, 'type');
// array content
// array = {options: [1, 2]];
key name of the array element
the value of the element if found, default value otherwise
Generated using TypeDoc
BaseDataHelper provides concrete implementation for DataHelper.
Do not use BaseDataHelper. Use DataHelper instead.