diff --git a/docs/reference/flow.rst b/docs/reference/flow.rst index 09dbe708d..609e2b128 100644 --- a/docs/reference/flow.rst +++ b/docs/reference/flow.rst @@ -92,7 +92,7 @@ Loop There are several ways in which this option can be used: * First it can be a **single component** of any type, an :js:class:`html.Screen`, (most likely) a :js:class:`flow.Sequence` or even another :js:class:`flow.Loop`. This component will be :js:func:`cloned ` for each iteration, and the :js:attr:`parameters ` substituted on each copy so that the repetitions can differ from another. - * Second, it can be a **function** that creates and returns the component for each iteration. This function will receive each set of :js:attr:`templateParameters ` in turn as a first argument (and, optionally, the index as a second argument). The advantage of this method is a greater flexibility: More logic can be used at every step to customize every iteration. + * Second, it can be a **function** that creates and returns the component for each iteration. This function will receive each set of :js:attr:`templateParameters ` in turn as a first argument (and, optionally, the index as a second argument, and the loop component itself as a third). The advantage of this method is a greater flexibility: Additional logic can be used at every step to customize every iteration. .. js:attribute:: options.templateParameters diff --git a/library/src/flow.js b/library/src/flow.js index 739ebf134..9c5d29be4 100644 --- a/library/src/flow.js +++ b/library/src/flow.js @@ -148,7 +148,7 @@ export class Loop extends Sequence { }) } else if (isFunction(this.options.template)) { this.options.content = this.options.templateParameters.map( - p => this.options.template(p, this), + (p, i) => this.options.template(p, i, this), ) } else { console.warn('Missing or invalid template in loop, no content generated')