Skip to content

Commit 7ca5401

Browse files
committed
[update] complete work with items guide for data collection
1 parent 895060e commit 7ca5401

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

docs/guides/datacollection/working_with_data_items.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ You can iterate through the items of a data collection, the items of a component
249249
### Iterating through the items of a data collection
250250

251251
The [`forEach()`](data_collection/api/datacollection_foreach_method.md) method iterates through all the items of a data collection. It takes as a parameter a callback function that will iterate over items of a data collection and is called with the following parameters:
252-
- `item` - (required) the object of an item
253-
- `index` - (optional) the index of an item
254-
- `array` - (optional) an array with items
252+
- `item` - the object of an item
253+
- `index` - the index of an item
254+
- `array` - an array with items
255255

256256
~~~jsx
257257
component.data.forEach(function(item, index, array) {
@@ -265,12 +265,17 @@ component.data.forEach(function(item, index, array) {
265265

266266
### Iterating through the items of a component
267267

268-
The [`map()`](data_collection/api/datacollection_map_method.md) method iterates through all the items of the component. As a parameter it takes a callback function that will be called for each item of a component and returns a new array of items where each item is the result of the callback function.
268+
The [`map()`](data_collection/api/datacollection_map_method.md) method iterates through all the items of the component. As a parameter it takes a callback function that will be called for each item of a component. The function is called with the following parameters:
269+
- `item` - the object of an item
270+
- `index` - the index of an item
271+
- `array` - an array of items the method was called upon
272+
273+
and returns a new array of items where each item is the result of the callback function.
269274

270275
~~~jsx
271276
// getting the ids of all the items of the component
272-
component.data.map(function(item){
273-
return item;
277+
component.data.map(function(item, index, array){
278+
return item.id;
274279
});
275280
~~~
276281

@@ -282,12 +287,15 @@ The [`mapRange()`](data_collection/api/datacollection_maprange_method.md) method
282287

283288
- `from: number` - the initial position of an item in the range
284289
- `to: number` - the final position of an item in the range
285-
- `callback: function` - a function that will be called for each item from the specified range
290+
- `callback: function` - a function that will be called for each item from the specified range. The function is called with the following parameters:
291+
- `item` - the object of an item
292+
- `index` - the index of an item
293+
- `array` - an array of items the method was called upon
286294

287295
and returns a new array of matching item objects.
288296

289297
~~~jsx
290-
const result = component.data.mapRange(0, 20, function(item, index) {
298+
const result = component.data.mapRange(0, 20, function(item, index, array) {
291299
console.log(item.id, index);
292300
});
293301
~~~

0 commit comments

Comments
 (0)