【发布时间】:2015-05-07 16:35:31
【问题描述】:
通常我可以使用fire 来激活处理程序,但在这种情况下,我需要在事件处理程序中使用e.context 获取完整的项目数据。
更新 08.05.15
详细说明
为什么我不能直接解雇node_action?
我有一个项目列表,点击时我想在项目附近的浮动块中显示项目相关信息。
所以我对每个项目都有on-tap='node_action',我有:
@on 'node_action', (e)->
item = e.context — then I can use item.id to load data
item_div = e.node — then I can use item_div.top_y() to show floating menu
on the same level on the page with the item div
为什么需要触发?
如果我想在那个浮动菜单上工作,我不想每次刷新页面后都手动点击项目,所以我通常会通过触发事件来自动化它。
是的,我可以在这里用准备好的事件来开火
e =
context: ractive.get 'items.0'
node: ractive.find '.items .line:first'
ractive.fire('node_action', e)
但列表中的项目可以排序、过滤和更改。
最好有这样的东西:
ractive.find('.items .line:first').tap()
或
ractive.find('.items .line:first').trigger 'tap'
或许
ractive.find('.items .line:first').fire 'node_action'
【问题讨论】:
标签: javascript dom-events ractivejs