Using JS functions with directives

On top of the predefined value assignment directive and iteration directive, you can as well use JS functions for more advanced needs.

var directive = {
  'tr@class':function(a){ ... }
}

It means:

The function must return a value.
This value will be assigned to the CLASS attribute of the TR tag.

Argument of the function

The argument of the function is an object with the following properties:

  • context : This is the full JSON that was passed for transformation
  • item* : the current loop item
  • items* : all the items of the loop
  • pos* : the current position in the loop. An integer when iterating an array, a property name iterating on a collection

The last 3 properties(*) are only present when the directive is inside a loop.

Note: If you debug a function, you'll notice there are other properties in the argument object.
They are all for backward compatibilities or internal use.
You shouldn't use them in your pages.

Here is an example: