forEachResultCell
The forEachResultCell
method takes a function that it will then call for each Cell
in the result Row
of a query.
forEachResultCell(
queryId: string,
rowId: string,
cellCallback: CellCallback,
): void
Type | Description | |
---|---|---|
queryId | string | The |
rowId | string | |
cellCallback | CellCallback | The function that should be called for every |
returns | void | This has no return value. |
This method is useful for iterating over each Cell
of the result Row
of the query in a functional style. The cellCallback
parameter is a CellCallback
function that will be called with the Id
and value of each result Cell
.
Example
This example iterates over each Cell
in a query's result Row
.
const store = createStore().setTable('pets', {
fido: {species: 'dog', color: 'brown'},
felix: {species: 'cat', color: 'black'},
cujo: {species: 'dog', color: 'black'},
});
const queries = createQueries(store).setQueryDefinition(
'dogColors',
'pets',
({select, where}) => {
select('species');
select('color');
where('species', 'dog');
},
);
queries.forEachResultCell('dogColors', 'fido', (cellId, cell) => {
console.log(`${cellId}: ${cell}`);
});
// -> 'species: dog'
// -> 'color: brown'
Since
v2.0.0