如何从模板中调用.hover。<template> .events api in coffeescript </template>

时间:2015-01-22 00:01:42

标签: jquery meteor coffeescript

在coffeescript中使用meteor的Template..events api时,如何为.hover注册两个必需的函数?

我尝试了以下几点:

Template.<template>.events
  'hover #elementID': (
     (ev) -> console.log 'hello world'
     (ev) -> console.log 'bye world'
   ) 

2 个答案:

答案 0 :(得分:11)

Saimeunt是正确的,但是如果你想要它完全像.hover()那么jquery会使用mouseenter和mouseleave。所以它是:

&#13;
&#13;
Template.<template>.events
  "mouseenter #elementID": (event, template) ->
    console.log "mousehover", event
  "mouseleave #elementID": (event, template) ->
    console.log "mouseout", event
&#13;
&#13;
&#13;

答案 1 :(得分:6)

正确的语法如下:

Template.myTemplate.events
  "mouseover #elementID": (event, template) ->
    console.log "mousehover", event
  "mouseout #elementID": (event, template) ->
    console.log "mouseout", event