Search
IEnumerable.forEach Method
See Also
 






Executes a provided function once for each element.

Namespace: MindFusion.Common.Collections
File: IEnumerable.js

 Syntax

JavaScript  Copy Code

function forEach (callback, context)

 Parameters

callback

function. A function to execute for each element.

context

Object. The invokation context.

 Example

The following code uses the forEach method in the event handler of the selectionChanged event of a ListView to change the background of items:

JavaScript  Copy Code

listView.selectionChanged.addEventListener(listSelectionChanged);

function listSelectionChanged(sender, args)
{
 if (args.oldItems)
 {
  args.oldItems.forEach(function (item)
  {
   item.data.style.backgroundColor = "";
  });
 }
 else
 {
  args.newItems.forEach(function (item)
  {
   item.data.style.backgroundColor = "#9caac6";
  });
 }
}

 See Also