can-EVENT
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
-
EVENT
{String}A event name like
clickorkeyup. If you are using jQuery, you can listen to jQuery special events too. -
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 byKEYis bound to the element'sEVENTevent. The function is called back with:context- the context of the elementelement- the element that was boundevent- the event that was triggeredSpecial 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:
The above template snippet would cause the save method (in the Mustache scope) whenever the user hits the enter key on this input.