can-EVENT

  • function
can.view.bindings.can-EVENT  

can-EVENT='KEY'

Specify a callback function to be called on a particular event. You can create your own special event types.

Parameters

  1. EVENT {String}

    A event name like click or keyup. If you are using jQuery, you can listen to jQuery special events too.

  2. key {key}

    A named value in the current scope. The value should be a function.

Use

By adding can-EVENT='KEY' to an element, the function pointed to by KEY is bound to the element's EVENT event. The function is called back with:

  • context - the context of the element
  • element - the element that was bound
  • event - the event that was triggered

Special Event Types

can.view.bindings supports creating special event types (events that aren't natively triggered by the DOM), which are bound by adding attributes like can-SPECIAL='KEY'. This is similar to $.special.

can-enter

can-enter is a special event that calls its handler whenever the enter key is pressed while focused on the current element. For example:

<input type='text' can-enter='save' />

The above template snippet would cause the save method (in the Mustache scope) whenever the user hits the enter key on this input.